You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just calling Py_Finalize forces Python to call atexit.register hook:
diff --git a/julia/python_jl.py b/julia/python_jl.py
index 5f4aad5..dc63a0a 100644
--- a/julia/python_jl.py+++ b/julia/python_jl.py@@ -40,6 +40,7 @@ import PyCall
PyCall.pyimport("julia")[:Julia](init_julia=false)
let code = PyCall.pyimport("julia.pseudo_python_cli")[:main](ARGS)
+ ccall(PyCall.@pysym(:Py_Finalize), Cvoid, ())
if code isa Integer
exit(code)
end
But it produces a segfault because PyCall has a bunch of references to PyObjects which are now pointing nowhere. (Maybe the problem with multiprocessing #206 (comment) also is relevant to this?)
$ python-jl -c 'from atexit import register; register(lambda: print("hello"))'hellosignal (11): Segmentation faultin expression starting at no file:0unknown function (ip: 0x7f48dcadd971)pydecref_ at /home/takafumi/.julia/dev/PyCall/src/PyCall.jl:102 [inlined]pydecref at /home/takafumi/.julia/dev/PyCall/src/PyCall.jl:107jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1537 [inlined]run_finalizer at /buildworker/worker/package_linux64/build/src/gc.c:115jl_gc_run_finalizers_in_list at /buildworker/worker/package_linux64/build/src/gc.c:210jl_gc_run_all_finalizers at /buildworker/worker/package_linux64/build/src/gc.c:245jl_atexit_hook at /buildworker/worker/package_linux64/build/src/init.c:260unknown function (ip: 0x40151c)__libc_start_main at /usr/lib/libc.so.6 (unknown line)unknown function (ip: 0x4015b4)Allocations: 11921591 (Pool: 11918737; Big: 2854); GC: 25
Activity
tkf commentedon Oct 27, 2018
Just calling
Py_Finalizeforces Python to callatexit.registerhook:But it produces a segfault because PyCall has a bunch of references to
PyObjects which are now pointing nowhere. (Maybe the problem with multiprocessing #206 (comment) also is relevant to this?)stevengj commentedon Oct 27, 2018
PyCall could probably check if Python is finalizing before calling decref?
tkf commentedon Oct 28, 2018
Yeah, I was thinking something like
But I haven't checked if it works.
Avoid segfault during exit process
Finalize Python runtime while shutting down Julia (#603)