mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
gh-113964: Don't prevent new threads until all non-daemon threads exit (#116677)
Starting in Python 3.12, we prevented calling fork() and starting new threads during interpreter finalization (shutdown). This has led to a number of regressions and flaky tests. We should not prevent starting new threads (or `fork()`) until all non-daemon threads exit and finalization starts in earnest. This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`, which is set immediately before terminating non-daemon threads.
This commit is contained in:
parent
025ef7a5f7
commit
60e105c1c1
8 changed files with 57 additions and 27 deletions
|
@ -7842,7 +7842,7 @@ os_fork1_impl(PyObject *module)
|
|||
pid_t pid;
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->finalizing) {
|
||||
if (_PyInterpreterState_GetFinalizing(interp) != NULL) {
|
||||
PyErr_SetString(PyExc_PythonFinalizationError,
|
||||
"can't fork at interpreter shutdown");
|
||||
return NULL;
|
||||
|
@ -7886,7 +7886,7 @@ os_fork_impl(PyObject *module)
|
|||
{
|
||||
pid_t pid;
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->finalizing) {
|
||||
if (_PyInterpreterState_GetFinalizing(interp) != NULL) {
|
||||
PyErr_SetString(PyExc_PythonFinalizationError,
|
||||
"can't fork at interpreter shutdown");
|
||||
return NULL;
|
||||
|
@ -8719,7 +8719,7 @@ os_forkpty_impl(PyObject *module)
|
|||
pid_t pid;
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->finalizing) {
|
||||
if (_PyInterpreterState_GetFinalizing(interp) != NULL) {
|
||||
PyErr_SetString(PyExc_PythonFinalizationError,
|
||||
"can't fork at interpreter shutdown");
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue