Skip to content

Commit 367d708

Browse files
committed
Call initialize and finalize from Python
1 parent 969f237 commit 367d708

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clr_loader/ffi/netfx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
typedef void* pyclr_domain;
66
typedef int (*entry_point)(void* buffer, int size);
77
8+
void pyclr_initialize();
89
void* pyclr_create_appdomain(const char* name, const char* config_file);
910
entry_point pyclr_get_function(pyclr_domain domain, const char* assembly_path, const char* class_name, const char* function);
1011
void pyclr_close_appdomain(pyclr_domain domain);
12+
void pyclr_finalize();
1113
"""
1214
]

clr_loader/netfx.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1+
import atexit
12
from .ffi import ffi, load_netfx
23

3-
44
_FW = None
55

66

77
class NetFx:
88
def __init__(self, name=None, config_file=None):
9-
global _FW
10-
if _FW is None:
11-
_FW = load_netfx()
12-
9+
initialize()
1310
self._domain = _FW.pyclr_create_appdomain(
1411
name or ffi.NULL, config_file or ffi.NULL
1512
)
@@ -27,3 +24,21 @@ def get_callable(self, assembly_path, typename, function):
2724
def __del__(self):
2825
if self._domain and _FW:
2926
_FW.pyclr_close_appdomain(self._domain)
27+
28+
29+
def initialize():
30+
global _FW
31+
if _FW is not None:
32+
return
33+
34+
_FW = load_netfx()
35+
_FW.pyclr_initialize()
36+
37+
atexit.register(_release)
38+
39+
40+
def _release():
41+
global _FW
42+
if _FW is not None:
43+
_FW.pyclr_finalize()
44+
_FW = None

0 commit comments

Comments
 (0)