diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-02-24 23:40:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-24 23:40:47 (GMT) |
commit | ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465 (patch) | |
tree | 9486fb50d2f39468a7c00de7fb5c05fdd67372e8 /Python/pylifecycle.c | |
parent | 463572c8beb59fd9d6850440af48a5c5f4c0c0c9 (diff) | |
download | cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.zip cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.tar.gz cpython-ef4ac967e2f3a9a18330cc6abe14adb4bc3d0465.tar.bz2 |
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (GH-11617)
This involves moving the global "pending calls" state to PyInterpreterState.
https://bugs.python.org/issue33608
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 8d0075a..eb0fddd 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) |