diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst new file mode 100644 index 00000000000000..d663be1867ed3d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-04-18-20-11.gh-issue-112275.W_iMiB.rst @@ -0,0 +1,3 @@ +A deadlock involving ``pystate.c``'s ``HEAD_LOCK`` in ``posixmodule.c`` +at fork is now fixed. Patch by ChuBoning based on previous Python 3.12 +fix by Victor Stinner. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 46859dab35c500..6fb2fc8ce250c1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -603,6 +603,11 @@ PyOS_AfterFork_Child(void) goto fatal_error; } + status = _PyRuntimeState_ReInitThreads(runtime); + if (_PyStatus_EXCEPTION(status)) { + goto fatal_error; + } + PyThreadState *tstate = _PyThreadState_GET(); _Py_EnsureTstateNotNULL(tstate); @@ -622,11 +627,6 @@ PyOS_AfterFork_Child(void) _PySignal_AfterFork(); - status = _PyRuntimeState_ReInitThreads(runtime); - if (_PyStatus_EXCEPTION(status)) { - goto fatal_error; - } - status = _PyInterpreterState_DeleteExceptMain(runtime); if (_PyStatus_EXCEPTION(status)) { goto fatal_error;