@@ -20,9 +20,8 @@ def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str):
20
20
21
21
self ._dotnet_root = Path (dotnet_root )
22
22
self ._dll = load_hostfxr (self ._dotnet_root )
23
- self ._is_initialized = False
24
23
self ._handle = _get_handle (self ._dll , self ._dotnet_root , runtime_config )
25
- self ._load_func = _get_load_func ( self . _dll , self . _handle )
24
+ self ._load_func = None
26
25
27
26
for key , value in params .items ():
28
27
self [key ] = value
@@ -36,7 +35,7 @@ def dotnet_root(self) -> Path:
36
35
37
36
@property
38
37
def is_initialized (self ) -> bool :
39
- return self ._is_initialized
38
+ return self ._load_func is not None
40
39
41
40
@property
42
41
def is_shutdown (self ) -> bool :
@@ -81,18 +80,23 @@ def __iter__(self) -> Generator[Tuple[str, str], None, None]:
81
80
for i in range (size_ptr [0 ]):
82
81
yield (decode (keys_ptr [i ]), decode (values_ptr [i ]))
83
82
83
+ def _get_load_func (self ):
84
+ if self ._load_func is None :
85
+ self ._load_func = _get_load_func (self ._dll , self ._handle )
86
+
87
+ return self ._load_func
88
+
84
89
def _get_callable (self , assembly_path : StrOrPath , typename : str , function : str ):
85
90
# TODO: Maybe use coreclr_get_delegate as well, supported with newer API
86
91
# versions of hostfxr
87
- self ._is_initialized = True
88
92
89
93
# Append assembly name to typename
90
94
assembly_path = Path (assembly_path )
91
95
assembly_name = assembly_path .stem
92
96
typename = f"{ typename } , { assembly_name } "
93
97
94
98
delegate_ptr = ffi .new ("void**" )
95
- res = self ._load_func (
99
+ res = self ._get_load_func () (
96
100
encode (str (assembly_path )),
97
101
encode (typename ),
98
102
encode (function ),
@@ -103,12 +107,6 @@ def _get_callable(self, assembly_path: StrOrPath, typename: str, function: str):
103
107
check_result (res )
104
108
return ffi .cast ("component_entry_point_fn" , delegate_ptr [0 ])
105
109
106
- def _check_initialized (self ) -> None :
107
- if self ._handle is None :
108
- raise RuntimeError ("Runtime is shut down" )
109
- elif not self ._is_initialized :
110
- raise RuntimeError ("Runtime is not initialized" )
111
-
112
110
def shutdown (self ) -> None :
113
111
if self ._handle is not None :
114
112
self ._dll .hostfxr_close (self ._handle )
0 commit comments