-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
sigsegv on exit for static PyObject Py_XDECREF #126508
Comments
(release) backtrace implies it wasn't able to get a non null OMState/interpreter (after skipping past the assert) at Line 1378 in 2e95c5b
|
If I understand correctly, segfault is raised on calling At this moment Python interpreter is already shut down and destroyed.
While segfault is not desired behavior, I'm curious what should we do here. Py_XDECREF cannot signal the error; in C we have no exceptions. I can propose a workaround that fixes the reproducer:
It can leave resources leaked, e.g. a file is not closed. Probably unclosed resource is not a problem, it will be released on the process exit. Anyway, decref could call Another (and maybe better) option is registering |
For the multiple interpreter case, will that necessitate some state management on the extension side? |
Yes probably. For multi-interpreter mode there is a recommendation to avoid static variables but put the shared data into the module state. See |
Yeah, I don't think there's anything that's a bug here. I highly suggest looking into multi-phase initialization and module state for calling things upon finalization.
Hmm, I'm not sure that will always work either. Acquiring the interpreter state is reliant on the thread state, which is probably cleared by the time the destructor gets called. You probably want |
Bug report
Bug description:
Noticed that on py312 a C extension I maintain is segfaulting when python exits. Managed to create a minimal C extension that reproduces the issue:
Minimal setup.py:
Occurs at least on linux amd64 and MacOS. Narrowed it down with git bisect to this commit: df3173d
CPython versions tested on:
3.12
Operating systems tested on:
Linux, macOS
The text was updated successfully, but these errors were encountered: