mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
bpo-33608: Deal with pending calls relative to runtime shutdown. (gh-12246)
This commit is contained in:
parent
7c4fcb6b05
commit
842a2f07f2
3 changed files with 70 additions and 22 deletions
|
@ -1049,17 +1049,21 @@ Py_FinalizeEx(void)
|
|||
if (!_PyRuntime.initialized)
|
||||
return status;
|
||||
|
||||
// Wrap up existing "threading"-module-created, non-daemon threads.
|
||||
wait_for_thread_shutdown();
|
||||
|
||||
/* Get current thread state and interpreter pointer */
|
||||
tstate = _PyThreadState_GET();
|
||||
interp = tstate->interp;
|
||||
|
||||
// Make any remaining pending calls.
|
||||
_Py_FinishPendingCalls();
|
||||
|
||||
/* The interpreter is still entirely intact at this point, and the
|
||||
* exit funcs may be relying on that. In particular, if some thread
|
||||
* or exit func is still waiting to do an import, the import machinery
|
||||
* expects Py_IsInitialized() to return true. So don't say the
|
||||
* interpreter is uninitialized until after the exit funcs have run.
|
||||
* runtime is uninitialized until after the exit funcs have run.
|
||||
* Note that Threading.py uses an exit func to do a join on all the
|
||||
* threads created thru it, so this also protects pending imports in
|
||||
* the threads created via Threading.
|
||||
|
@ -1462,6 +1466,7 @@ Py_EndInterpreter(PyThreadState *tstate)
|
|||
Py_FatalError("Py_EndInterpreter: thread still has a frame");
|
||||
interp->finalizing = 1;
|
||||
|
||||
// Wrap up existing "threading"-module-created, non-daemon threads.
|
||||
wait_for_thread_shutdown();
|
||||
|
||||
call_py_exitfuncs(interp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue