Skip to content

Commit 58bd58c

Browse files
committed
Ensure that shutdown is called from Python
1 parent e9cbb87 commit 58bd58c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pythonnet/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_runtime(runtime):
1616

1717

1818
def set_default_runtime() -> None:
19-
if sys.platform == 'win32':
19+
if sys.platform == "win32":
2020
set_runtime(clr_loader.get_netfx())
2121
else:
2222
set_runtime(clr_loader.get_mono())
@@ -36,22 +36,23 @@ def load():
3636
set_default_runtime()
3737

3838
dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll")
39-
39+
4040
_LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path)
4141

4242
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]
43-
if func(''.encode("utf8")) != 0:
43+
if func(b"") != 0:
4444
raise RuntimeError("Failed to initialize Python.Runtime.dll")
4545

4646
import atexit
47+
4748
atexit.register(unload)
4849

4950

5051
def unload():
5152
global _RUNTIME
5253
if _LOADER_ASSEMBLY is not None:
5354
func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Shutdown"]
54-
if func(b"") != 0:
55+
if func(b"full_shutdown") != 0:
5556
raise RuntimeError("Failed to call Python.NET shutdown")
5657

5758
if _RUNTIME is not None:

0 commit comments

Comments
 (0)