gh-98608: Fix Failure-handling in new_interpreter() (gh-102658) · python/cpython@d1b883b (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit d1b883b

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.#98608

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -2062,10 +2062,10 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
2062 2062
2063 2063 /* Oops, it didn't work. Undo it all. */
2064 2064 PyErr_PrintEx(0);
2065 +PyThreadState_Swap(save_tstate);
2065 2066 PyThreadState_Clear(tstate);
2066 2067 PyThreadState_Delete(tstate);
2067 2068 PyInterpreterState_Delete(interp);
2068 -PyThreadState_Swap(save_tstate);
2069 2069
2070 2070 return status;
2071 2071 }