🌐 AI搜索 & 代理 主页
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions pythonnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def load():
if _LOADED:
return

from .find_libpython import linked_libpython
from os.path import join, dirname

if _RUNTIME is None:
Expand All @@ -38,21 +37,11 @@ def load():
set_default_runtime()

dll_path = join(dirname(__file__), "runtime", "Python.Runtime.dll")
libpython = linked_libpython()

if libpython and _FFI is None and sys.platform != "win32":
# Load and leak libpython handle s.t. the .NET runtime doesn't dlcloses
# it
import posix

import cffi
_FFI = cffi.FFI()
_FFI.dlopen(libpython, posix.RTLD_NODELETE | posix.RTLD_LOCAL)


_LOADER_ASSEMBLY = _RUNTIME.get_assembly(dll_path)

func = _LOADER_ASSEMBLY["Python.Runtime.Loader.Initialize"]
if func(f"{libpython or ''}".encode("utf8")) != 0:
if func(''.encode("utf8")) != 0:
raise RuntimeError("Failed to initialize Python.Runtime.dll")

import atexit
Expand Down