-
Notifications
You must be signed in to change notification settings - Fork 682
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
Drop
trait never called on exit
#4092
Comments
Regardless of if this instance can be fixed, relying on destructors being called at program exit is a recipe for sadness when Python is involved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello there, I have an issue on program exit where the
Drop
trait of aPyClass
object doesn't get called when python is exitting. I first encountered it in an extension module I am working on, but it seems to happen also when it is rust initializing python.Here is minimal example
Using
pyo3==0.21.2
or lower, andpython==3.11.2
I get the following outputI would have expected to see
drop 1
somewhere, likely afterending
andmain
exit, when the started python interpreter stops and reacquire its GIL to drop all its objects. Instead it seems the object is never dropped.If I reacquire the GIL before leaving
main
(uncommenting the last line) I finally get what's expected.In this example, reacquire the GIL at the end of the main seems to be a workaround, but it is not in the case of an extension module where you do not know when the program will stop and thus cannot insert this GIL acquisition.
In my usecase, I need to properly stop rust threads in
drop
Do you have an idea of what to do in order to ensure
drop
will be called ?The text was updated successfully, but these errors were encountered: