Skip to content

Do not call find_libpython during import clr as Python.Runtime can find it on its own #1440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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