Skip to content
Prev Previous commit
Next Next commit
Also check the thread ID in _PyThreadState_MustExit().
  • Loading branch information
ericsnowcurrently committed Sep 23, 2023
commit a1014a924ce126707d6b525eef5794a45eb19deb
12 changes: 11 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,17 @@ _PyThreadState_MustExit(PyThreadState *tstate)
if (finalizing == NULL) {
finalizing = _PyInterpreterState_GetFinalizing(tstate->interp);
}
return (finalizing != NULL && finalizing != tstate);
if (finalizing == NULL) {
return 0;
}
else if (finalizing == tstate) {
return 0;
}
else if (finalizing->thread_id == tstate->thread_id) {
/* gh-109793: we must have switched interpreters. */
return 0;
}
return 1;
}


Expand Down