Skip to content

Commit d5fdc3f

Browse files
gh-98608: Fix Failure-handling in new_interpreter() (gh-102658)
The error-handling code in new_interpreter() has been broken for a while. We hadn't noticed because those code mostly doesn't fail. (I noticed while working on gh-101660.) The problem is that we try to clear/delete the newly-created thread/interpreter using itself, which just failed. The solution is to switch back to the calling thread state first. (cherry picked from commit d1b883b) Co-authored-by: Eric Snow <[email protected]> https: //github.com//issues/98608
1 parent e732a85 commit d5fdc3f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Python/pylifecycle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1962,10 +1962,10 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
19621962

19631963
/* Oops, it didn't work. Undo it all. */
19641964
PyErr_PrintEx(0);
1965+
PyThreadState_Swap(save_tstate);
19651966
PyThreadState_Clear(tstate);
19661967
PyThreadState_Delete(tstate);
19671968
PyInterpreterState_Delete(interp);
1968-
PyThreadState_Swap(save_tstate);
19691969

19701970
return status;
19711971
}

0 commit comments

Comments
 (0)