From 5b944a323e2f0b11d7b5252aac6f6a5558a5b1fc Mon Sep 17 00:00:00 2001 From: Dani Pinyol Date: Tue, 21 Apr 2026 16:31:16 +0200 Subject: [PATCH] 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 --- pysrc/juliacall/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pysrc/juliacall/__init__.py b/pysrc/juliacall/__init__.py index 62fa5a51..7af287e1 100644 --- a/pysrc/juliacall/__init__.py +++ b/pysrc/juliacall/__init__.py @@ -249,10 +249,15 @@ def args_from_config(config): # including running finalizers for any objects that still exist @atexit.register def at_jl_exit(): - jl_atexit_hook = lib.jl_atexit_hook - jl_atexit_hook.argtypes = [c.c_int] - jl_atexit_hook.restype = None - jl_atexit_hook(0) + jl_eval(b''' + try + Base._atexit(Int32(0)) + flush(Base.stdout) + flush(Base.stderr) + catch e + @error "Error during Julia atexit" e + end; + ''') # initialise PythonCall jl_eval = lib.jl_eval_string