HEAD_LOCK is called from _PyEval_ReInitThreads->_PyThreadState_DeleteExcept before _PyRuntimeState_ReInitThreads reinit runtime->interpreters.mutex which might be locked before fork.
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
--- /dev/null
+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.
goto fatal_error;
}
+ status = _PyRuntimeState_ReInitThreads(runtime);
+ if (_PyStatus_EXCEPTION(status)) {
+ goto fatal_error;
+ }
+
PyThreadState *tstate = _PyThreadState_GET();
_Py_EnsureTstateNotNULL(tstate);
_PySignal_AfterFork();
- status = _PyRuntimeState_ReInitThreads(runtime);
- if (_PyStatus_EXCEPTION(status)) {
- goto fatal_error;
- }
-
status = _PyInterpreterState_DeleteExceptMain(runtime);
if (_PyStatus_EXCEPTION(status)) {
goto fatal_error;