[Python-checkins] gh-98608: Fix Failure-handling in new_interpreter() (gh-102658)

miss-islington webhook-mailer at python.org
Tue Mar 21 15:13:40 EDT 2023


https://github.com/python/cpython/commit/4c6b354699c2967879b9c99fe247c4d97f0e31f9
commit: 4c6b354699c2967879b9c99fe247c4d97f0e31f9
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2023-03-21T12:13:31-07:00
summary:

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 d1b883b52a99427d234c20e4a92ddfa6a1da8880)

Co-authored-by: Eric Snow <ericsnowcurrently at gmail.com>
https: //github.com/python/cpython/issues/98608

files:
M Python/pylifecycle.c

diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 4060c23ace1c..9248e971d9c7 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2028,10 +2028,10 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
 
     /* Oops, it didn't work.  Undo it all. */
     PyErr_PrintEx(0);
+    PyThreadState_Swap(save_tstate);
     PyThreadState_Clear(tstate);
     PyThreadState_Delete(tstate);
     PyInterpreterState_Delete(interp);
-    PyThreadState_Swap(save_tstate);
 
     return status;
 }



More information about the Python-checkins mailing list