diff options
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 8d0075a48d..eb0fdddb4b 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1459,8 +1459,32 @@ Py_EndInterpreter(PyThreadState *tstate) if (tstate->frame != NULL) Py_FatalError("Py_EndInterpreter: thread still has a frame"); + // Mark as finalizing. + if (interp->ceval.pending.lock != NULL) { + PyThread_acquire_lock(interp->ceval.pending.lock, 1); + } + interp->finalizing = 1; + if (interp->ceval.pending.lock != NULL) { + PyThread_release_lock(interp->ceval.pending.lock); + } + + // Wrap up existing threads. wait_for_thread_shutdown(); + // Make any pending calls. + if (_Py_atomic_load_relaxed( + &(interp->ceval.pending.calls_to_do))) + { + // XXX Ensure that the interpreter is running in the current thread? + if (_Py_MakePendingCalls(interp) < 0) { + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); + PyErr_BadInternalCall(); + _PyErr_ChainExceptions(exc, val, tb); + PyErr_Print(); + } + } + call_py_exitfuncs(interp); if (tstate != interp->tstate_head || tstate->next != NULL) |