Skip to content

Commit 5b944a3

Browse files
author
Dani Pinyol
committed
fix: random crash atexit with multithread julia
Invoke Base._atexit instead of jl_atexit_hook to avoid invoking finalizers, which might crash with multithread julia
1 parent 8f7baa5 commit 5b944a3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

pysrc/juliacall/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,15 @@ def args_from_config(config):
249249
# including running finalizers for any objects that still exist
250250
@atexit.register
251251
def at_jl_exit():
252-
jl_atexit_hook = lib.jl_atexit_hook
253-
jl_atexit_hook.argtypes = [c.c_int]
254-
jl_atexit_hook.restype = None
255-
jl_atexit_hook(0)
252+
jl_eval(b'''
253+
try
254+
Base._atexit(Int32(0))
255+
flush(Base.stdout)
256+
flush(Base.stderr)
257+
catch e
258+
@error "Error during Julia atexit" e
259+
end;
260+
''')
256261

257262
# initialise PythonCall
258263
jl_eval = lib.jl_eval_string

0 commit comments

Comments
 (0)