File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -754,12 +754,18 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
754
754
_PyErr_Clear (tstate );
755
755
}
756
756
757
+ // Clear the current/main thread state last.
757
758
HEAD_LOCK (runtime );
758
- // XXX Clear the current/main thread state last.
759
- for (PyThreadState * p = interp -> threads .head ; p != NULL ; p = p -> next ) {
759
+ PyThreadState * p = interp -> threads .head ;
760
+ HEAD_UNLOCK (runtime );
761
+ while (p != NULL ) {
762
+ // Must be called without HEAD_LOCK held as it can deadlock
763
+ // if any finalizer tries to acquire that lock.
760
764
PyThreadState_Clear (p );
765
+ HEAD_LOCK (runtime );
766
+ p = p -> next ;
767
+ HEAD_UNLOCK (runtime );
761
768
}
762
- HEAD_UNLOCK (runtime );
763
769
764
770
/* It is possible that any of the objects below have a finalizer
765
771
that runs Python code or otherwise relies on a thread state
You can’t perform that action at this time.
0 commit comments