Call Py_FinalizeEx() when process exits#187
Draft
snickell wants to merge 9 commits intored-data-tools:masterfrom
Draft
Call Py_FinalizeEx() when process exits#187snickell wants to merge 9 commits intored-data-tools:masterfrom
snickell wants to merge 9 commits intored-data-tools:masterfrom
Conversation
Works, but gives warnings and of limited use. This reverts commit ef4cbe2.
Author
|
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. |
Author
|
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.initializebefore it exits. Then the main thread will exit properly. Unfortunately, it is not possible to automatically callPyCall.initializein a side-thread, becauseat_exitonly 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.