Skip to content

Commit 6a38f18

Browse files
author
Christopher Doris
committed
use a global to pass libptr instead of an env var
1 parent ffdac16 commit 6a38f18

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pysrc/juliacall/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def jlstr(x):
194194
try
195195
Base.require(Main, :CompilerSupportLibraries_jll)
196196
import Pkg
197-
ENV["JULIA_PYTHONCALL_LIBPTR"] = {}
197+
global __PythonCall_libptr = Ptr{{Cvoid}}(UInt({}))
198198
ENV["JULIA_PYTHONCALL_EXE"] = {}
199199
Pkg.activate({}, io=devnull)
200200
import PythonCall
@@ -205,7 +205,7 @@ def jlstr(x):
205205
rethrow()
206206
end
207207
'''.format(
208-
jlstr(str(c.pythonapi._handle)),
208+
hex(c.pythonapi._handle),
209209
jlstr(sys.executable or ''),
210210
jlstr(project),
211211
)

src/cpython/context.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ end
3232

3333
function init_context()
3434

35-
CTX.is_embedded = haskey(ENV, "JULIA_PYTHONCALL_LIBPTR")
35+
CTX.is_embedded = hasproperty(Base.Main, :__PythonCall_libptr)
3636

3737
if CTX.is_embedded
3838
# In this case, getting a handle to libpython is easy
39-
CTX.lib_ptr = Ptr{Cvoid}(parse(UInt, ENV["JULIA_PYTHONCALL_LIBPTR"]))
39+
CTX.lib_ptr = Base.Main.__PythonCall_libptr::Ptr{Cvoid}
4040
init_pointers()
4141
# Check Python is initialized
4242
Py_IsInitialized() == 0 && error("Python is not already initialized.")
@@ -48,10 +48,6 @@ function init_context()
4848
# this ensures PyCall uses the same Python interpreter
4949
get!(ENV, "PYTHON", exe_path)
5050
end
51-
# On success, delete JULIA_PYTHONCALL_LIBPTR so that further processes do not think
52-
# they are embedded in Python (e.g. this can happen when precompiling).
53-
# See https://github.com/cjdoris/PythonCall.jl/issues/235
54-
delete!(ENV, "JULIA_PYTHONCALL_LIBPTR")
5551
else
5652
# Find Python executable
5753
exe_path = get(ENV, "JULIA_PYTHONCALL_EXE", "")

0 commit comments

Comments
 (0)