Call initialize and finalize from Python
This commit is contained in:
Родитель
969f237223
Коммит
367d708239
|
@ -5,8 +5,10 @@ cdef = [
|
|||
typedef void* pyclr_domain;
|
||||
typedef int (*entry_point)(void* buffer, int size);
|
||||
|
||||
void pyclr_initialize();
|
||||
void* pyclr_create_appdomain(const char* name, const char* config_file);
|
||||
entry_point pyclr_get_function(pyclr_domain domain, const char* assembly_path, const char* class_name, const char* function);
|
||||
void pyclr_close_appdomain(pyclr_domain domain);
|
||||
void pyclr_finalize();
|
||||
"""
|
||||
]
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
import atexit
|
||||
from .ffi import ffi, load_netfx
|
||||
|
||||
|
||||
_FW = None
|
||||
|
||||
|
||||
class NetFx:
|
||||
def __init__(self, name=None, config_file=None):
|
||||
global _FW
|
||||
if _FW is None:
|
||||
_FW = load_netfx()
|
||||
|
||||
initialize()
|
||||
self._domain = _FW.pyclr_create_appdomain(
|
||||
name or ffi.NULL, config_file or ffi.NULL
|
||||
)
|
||||
|
@ -27,3 +24,21 @@ class NetFx:
|
|||
def __del__(self):
|
||||
if self._domain and _FW:
|
||||
_FW.pyclr_close_appdomain(self._domain)
|
||||
|
||||
|
||||
def initialize():
|
||||
global _FW
|
||||
if _FW is not None:
|
||||
return
|
||||
|
||||
_FW = load_netfx()
|
||||
_FW.pyclr_initialize()
|
||||
|
||||
atexit.register(_release)
|
||||
|
||||
|
||||
def _release():
|
||||
global _FW
|
||||
if _FW is not None:
|
||||
_FW.pyclr_finalize()
|
||||
_FW = None
|
||||
|
|
Загрузка…
Ссылка в новой задаче