Skip to content

Commit 158e17b

Browse files
author
Christopher Doris
committed
only warn python is exiting when we own the python session
1 parent 14d2e13 commit 158e17b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/cpython/context.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
const CTX = Context()
2424

2525
function _atpyexit()
26-
if CTX.is_initialized && CTX.which != :PyCall
26+
if CTX.is_initialized && !CTX.is_preinitialized
2727
@warn "Python exited unexpectedly"
2828
end
2929
CTX.is_initialized = false
@@ -40,7 +40,7 @@ function init_context()
4040
init_pointers()
4141
# Check Python is initialized
4242
Py_IsInitialized() == 0 && error("Python is not already initialized.")
43-
CTX.is_initialized = CTX.is_preinitialized = true
43+
CTX.is_initialized = true
4444
CTX.which = :embedded
4545
exe_path = get(ENV, "JULIA_PYTHONCALL_EXE", "")
4646
if exe_path != ""
@@ -121,7 +121,8 @@ function init_context()
121121

122122
# Initialize
123123
with_gil() do
124-
if Py_IsInitialized() != 0
124+
CTX.is_preinitialized = Py_IsInitialized() != 0
125+
if CTX.is_preinitialized
125126
# Already initialized (maybe you're using PyCall as well)
126127
@assert CTX.which in (:embedded, :PyCall)
127128
else

0 commit comments

Comments
 (0)