Skip to content

Commit 00774fb

Browse files
committed
Support calling PyCall.npyinitialize() during sysimage compilation
In PR JuliaPy#651, I introduced code to empty `npy_api` in `__init__` but forgot to reset `npy_initialized`. This introduces a bug if `npyinitialize` is called during sysimage compilation (`--output-o` mode) because the main body of `npyinitialize` is not run at run-time.
1 parent fffd933 commit 00774fb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

aot/precompile.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ isdefined(MacroTools, :__init__) && MacroTools.__init__()
1414
using PyCall
1515
PyCall.__init__()
1616
PyCall.pyimport("sys")[:executable]
17+
18+
has_numpy = try
19+
PyCall.pyimport("numpy")
20+
true
21+
catch
22+
false
23+
end
24+
if has_numpy
25+
# Invoke numpy support (which mutates various states in PyCall) to
26+
# test that it does not introduce any run-time bugs:
27+
PyCall.npyinitialize()
28+
end

src/pyinit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function __init__()
131131
_finalized[] = false
132132
empty!(_namespaces)
133133
empty!(eventloops)
134+
global npy_initialized = false
134135
empty!(npy_api)
135136
empty!(pycall_gc)
136137
empty!(pyexc)

0 commit comments

Comments
 (0)