You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_Py_IsFinalizing has been removed, meaning C/C++ threads cannot avoid termination during shutdown #108014
_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.
FYI, there is some work to hang remaining threads rather than killing them: gh-105805. I expect that would land in 3.13.
Presumably a Py_IsFinalizing() would still be helpful though.
Activity
vstinner commentedon Aug 16, 2023
Since
sys.is_finalizing()was added to Python 3.5, IMO it's fine to add a public C API function for that: https://docs.python.org/dev/library/sys.html#sys.is_finalizingcc @ericsnowcurrently
pythongh-108014: Add Py_IsFinalizing() function
ericsnowcurrently commentedon Aug 16, 2023
FYI, there is some work to hang remaining threads rather than killing them: gh-105805. I expect that would land in 3.13.
Presumably a
Py_IsFinalizing()would still be helpful though.erlend-aasland commentedon Aug 17, 2023
I think it would make sense to also make
_Py_IsInterpreterFinalizingpublic:cpython/Python/pylifecycle.c
Lines 2181 to 2191 in 1344cfa
gh-108014: Add Py_IsFinalizing() function (#108032)
vstinner commentedon Aug 18, 2023
Function added by commit 3ff5ef2.
vstinner commentedon Aug 18, 2023
Function added to pythoncapi-compat by commit python/pythoncapi-compat@1bb4e16.
vstinner commentedon Sep 25, 2023
I proposed adding PythonFinalizationError exception in PR gh-109809.
vstinner commentedon Oct 5, 2023
Follow-up: @wjakob asks to add this new function to the limited C API version 3.13.