Skip to content

Commit 236beca

Browse files
committed
Defer clearing last thread state until last GC has been run.
1 parent b51081c commit 236beca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/pystate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
292292

293293
HEAD_LOCK(runtime);
294294
for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) {
295-
PyThreadState_Clear(p);
295+
if (p != tstate) {
296+
PyThreadState_Clear(p);
297+
}
296298
}
297299
HEAD_UNLOCK(runtime);
298300

@@ -324,6 +326,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
324326

325327
/* Last garbage collection on this interpreter */
326328
_PyGC_CollectNoFail(tstate);
329+
PyThreadState_Clear(tstate);
327330
_PyGC_Fini(interp);
328331

329332
/* We don't clear sysdict and builtins until the end of this function.

0 commit comments

Comments
 (0)