mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-104341: Adjust tstate_must_exit() to Respect Interpreter Finalization (gh-104437)
With the move to a per-interpreter GIL, this check slipped through the cracks.
This commit is contained in:
parent
cb88ae635e
commit
26baa747c2
11 changed files with 56 additions and 10 deletions
|
@ -1788,6 +1788,7 @@ Py_FinalizeEx(void)
|
|||
|
||||
/* Remaining daemon threads will automatically exit
|
||||
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */
|
||||
_PyInterpreterState_SetFinalizing(tstate->interp, tstate);
|
||||
_PyRuntimeState_SetFinalizing(runtime, tstate);
|
||||
runtime->initialized = 0;
|
||||
runtime->core_initialized = 0;
|
||||
|
@ -2142,6 +2143,10 @@ Py_EndInterpreter(PyThreadState *tstate)
|
|||
Py_FatalError("not the last thread");
|
||||
}
|
||||
|
||||
/* Remaining daemon threads will automatically exit
|
||||
when they attempt to take the GIL (ex: PyEval_RestoreThread()). */
|
||||
_PyInterpreterState_SetFinalizing(interp, tstate);
|
||||
|
||||
// XXX Call something like _PyImport_Disable() here?
|
||||
|
||||
_PyImport_FiniExternal(tstate->interp);
|
||||
|
@ -2152,6 +2157,18 @@ Py_EndInterpreter(PyThreadState *tstate)
|
|||
finalize_interp_delete(tstate->interp);
|
||||
}
|
||||
|
||||
int
|
||||
_Py_IsInterpreterFinalizing(PyInterpreterState *interp)
|
||||
{
|
||||
/* We check the runtime first since, in a daemon thread,
|
||||
interp might be dangling pointer. */
|
||||
PyThreadState *finalizing = _PyRuntimeState_GetFinalizing(&_PyRuntime);
|
||||
if (finalizing == NULL) {
|
||||
finalizing = _PyInterpreterState_GetFinalizing(interp);
|
||||
}
|
||||
return finalizing != NULL;
|
||||
}
|
||||
|
||||
/* Add the __main__ module */
|
||||
|
||||
static PyStatus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue