summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 6331a854c8..8f0b6b87d6 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -765,11 +765,19 @@ PyThreadState_Clear(PyThreadState *tstate)
{
int verbose = tstate->interp->config.verbose;
- if (verbose && tstate->frame != NULL)
+ if (verbose && tstate->frame != NULL) {
+ /* bpo-20526: After the main thread calls
+ _PyRuntimeState_SetFinalizing() in Py_FinalizeEx(), threads must
+ exit when trying to take the GIL. If a thread exit in the middle of
+ _PyEval_EvalFrameDefault(), tstate->frame is not reset to its
+ previous value. It is more likely with daemon threads, but it can
+ happen with regular threads if threading._shutdown() fails
+ (ex: interrupted by CTRL+C). */
fprintf(stderr,
"PyThreadState_Clear: warning: thread still has a frame\n");
+ }
- Py_CLEAR(tstate->frame);
+ /* Don't clear tstate->frame: it is a borrowed reference */
Py_CLEAR(tstate->dict);
Py_CLEAR(tstate->async_exc);