From 38ca12467c0105060d60e4106193cc74e9506bd9 Mon Sep 17 00:00:00 2001 From: Abdul Mohammad <154353563+abdulm5@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:12:24 -0400 Subject: [PATCH] gh-155504: Set the interpreter before fallible thread state initialization (GH-155590) (cherry picked from commit 94a75f74a13a11b4025c02612c47f61dec0a7398) Co-authored-by: Abdul Mohammad <154353563+abdulm5@users.noreply.github.com> --- .../2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst | 2 ++ Python/pystate.c | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-11-13-50-35.gh-issue-155504.PsTqZm.rst 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 d1505be4acf50f..5de6defb4bdc3e 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1506,6 +1506,8 @@ alloc_threadstate(PyInterpreterState *interp) } reset_threadstate(tstate); } + // Set the interpreter before any later initialization can fail. + tstate->base.interp = interp; return tstate; }