https://github.com/python/cpython/commit/ccbdd1fba6bbdb56d1701c8d9231d6d170f20ed5
commit: ccbdd1fba6bbdb56d1701c8d9231d6d170f20ed5
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-10-10T13:27:53+03:00
summary:

[3.15] gh-155504: Set the interpreter before fallible thread state 
initialization (GH-155590) (GH-155884)

(cherry picked from commit 94a75f74a13a11b4025c02612c47f61dec0a7398)

Co-authored-by: Abdul Mohammad <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst
M Python/pystate.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst
new file mode 100644
index 00000000000000..e042bf3554e6f0
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst
@@ -0,0 +1,2 @@
+Fix a crash when thread state creation fails before the thread state is fully
+initialized.
diff --git a/Python/pystate.c b/Python/pystate.c
index 4cfb873c71c37e..9ac726e63b6bb9 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1479,6 +1479,8 @@ alloc_threadstate(PyInterpreterState *interp)
         }
         reset_threadstate(tstate);
     }
+    // Set the interpreter before any later initialization can fail.
+    tstate->base.interp = interp;
     return tstate;
 }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to