-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call Py_FinalizeEx() when process exits #187
base: master
Are you sure you want to change the base?
Conversation
Works, but gives warnings and of limited use. This reverts commit ef4cbe2.
This may still have issues with pandas 🐼: after the finalize, when the process exits, it segfaults after the at_exit handlers. I need to figure out how to debug this in lldb. |
It might be necessary to unregister gc objects before calling Investigating DestructorsWhen a Ruby-refs-Python object is destroyed by Ruby:PyCall.gcguard_table (class is gcguard_data_type in C)Initialized when pycall.so starts:
When PyCall.gcguard_table is destroyed by Ruby:
When a Python-refs-Ruby object is destroyed by Python:
pycall_gcguard_register(), does not appear to be used (?)pycall_gcguard_register() registers weak-refs to Python objects, which call
Initializing pycall.so registers the weakref_callback_pyobj() callback:
|
Fixes #186
Currently: if you use PyCall from a "side thread" (="not the main thread), when you exit the process does not exit. See #186 for more information.
Using this PR, the "side thread" may manually call
PyCall.initialize
before it exits. Then the main thread will exit properly. Unfortunately, it is not possible to automatically callPyCall.initialize
in a side-thread, becauseat_exit
only runs on the main thread, and there is no handler for thread.on_exit.This PR:
PyCall.finalize()
, which calls Py_FinalizeEx()PyCall.finalize()
at_exit, if initialized on the main threadA secondary advantage of this PR: it cleans up python memory before exit, which might make it easier to use valgrind and other memory debugging tools.
Example using this PR:
Before this PR (=comment out PyCall.finalize), the process would never exit even after both threads exited.