-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
_Py_IsFinalizing has been removed, meaning C/C++ threads cannot avoid termination during shutdown #108014
Comments
Since |
FYI, there is some work to hang remaining threads rather than killing them: gh-105805. I expect that would land in 3.13. |
I think it would make sense to also make Lines 2181 to 2191 in 1344cfa
|
Co-authored-by: Serhiy Storchaka <[email protected]>
Function added by commit 3ff5ef2. |
Function added to pythoncapi-compat by commit python/pythoncapi-compat@1bb4e16. |
I proposed adding PythonFinalizationError exception in PR gh-109809. |
Follow-up: @wjakob asks to add this new function to the limited C API version 3.13. |
Checklist
and am confident this bug has not been reported before
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.0a0 (main, Jul 29 2023, 00:25:05) [GCC 13.1.1 20230614 (Red Hat 13.1.1-4)]
A clear and concise description of the bug:
Threads that call PyEval_RestoreThread while the runtime is finalizing are terminated. The documented way to avoid this is to call _Py_IsFinalizing() to check. https://docs.python.org/3.13/c-api/init.html#c.PyEval_RestoreThread
_Py_IsFinalizing() has been removed from Python 3.13. Please provide a public API function that has the equivalent behavior, or some other way for a non-Python thread to safely attempt to call into Python code when the interpreter may be finalizing.
Rather than the calling code checking for finalization, an alternative solution would be to provide a variant of PyEval_RestoreThread that returns success or failure, so the calling code can know that it was unable to acquire the GIL, and react accordingly.
Linked PRs
The text was updated successfully, but these errors were encountered: