summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2019-03-15 15:47:51 -0600
committerGitHub <noreply@github.com>2019-03-15 15:47:51 -0600
commit842a2f07f2f08a935ef470bfdaeef40f87490cfc (patch)
tree33d887ff84afb3190bf53627ebb53f586cd086b9 /Python/pylifecycle.c
parent7c4fcb6b05792e94dd5f8aca032f01314248f5ac (diff)
downloadcpython-git-842a2f07f2f08a935ef470bfdaeef40f87490cfc.tar.gz
bpo-33608: Deal with pending calls relative to runtime shutdown. (gh-12246)
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 0902508429..c2d431c912 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -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);