Repository navigation
[BUG]: Python atexit broken with pybind11 version >= 2.9.2 #4459
Description
Activity
FYI @rwgk
@chrreisinger could you help by
- creating a PR that moves the
.clear()calls after thePy_Finalize()call, - and ideally adds a unit test for your situation (in tests/test_embed/test_interpreter.cpp)?
The change makes sense to me. My understanding is: the
Py_Finalize()invalidates allPyObject*pointers in thelocal_internals, but looking at thestruct local_internalscode, it seems to me the.clear()calls don't ever use those pointers. There are a bunch of non-trivial destructors that will run, but none of them will call into the Python C API.- creating a PR that moves the
I will give it a try on the weekend.
I will give it a try on the weekend.
Awesome.
If you create a PR with just the lines moved, that'll be a great start. It will be good to confirm that valgrind does not find any issues. We can work on the test together from there.
@chrreisinger Any updates on this?
- added a commit that references this issue
on Feb 2, 2023 - added a commit that references this issue
on Feb 6, 2023 - added a commit that references this issue
on Feb 8, 2023 Oh boy, this broke some more things.
- added a commit that references this issue
on Feb 8, 2023 🤖 AI text below 🤖
The finalization order was rewritten by #5564.
embed.hnow callsPy_Finalize()before it destroys the internals, which is what this issue asked for. Pythonatexithandlers therefore run while the bindings are still alive.If you can still reproduce this with current master (v3), please comment and we can reopen.
Required prerequisites
What version (or hash if on master) of pybind11 are you using?
2.10.2
Problem description
We want to upgrade from pybind11 release 2.9.0 to 2.10.2, but we encountered an issue in the Python atexit (https://docs.python.org/3/library/atexit.html) functions, that our custom types are not registered anymore. With delta debugging we found that this PR caused the issue: #3744
In my opinion the
calls should be after the Py_Finalize function call.
When I change the orders of those function calls, the problem is gone.
Reproducible example code
No response
Is this a regression? Put the last known working version here if it is.
2.9.1