Skip to content

Commit

Permalink
[3.9] pythongh-112275: Fix HEAD_LOCK deadlock in child process after …
Browse files Browse the repository at this point in the history
…fork (pythonGH-112336) (pythonGH-123688)

HEAD_LOCK is called from _PyEval_ReInitThreads->_PyThreadState_DeleteExcept before _PyRuntimeState_ReInitThreads reinit runtime->interpreters.mutex which might be locked before fork.

(cherry picked from commit 522799a)

(cherry picked from commit 0152431)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: ChuBoning <102216855+ChuBoning@users.noreply.github.com>
  • Loading branch information
2 people authored and miss-islington committed Sep 4, 2024
1 parent 2309739 commit a8e5483
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ PyOS_AfterFork_Child(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
_PyGILState_Reinit(runtime);
_PyRuntimeState_ReInitThreads(runtime);
_PyEval_ReInitThreads(runtime);
_PyImport_ReInitLock();
_PySignal_AfterFork();
_PyRuntimeState_ReInitThreads(runtime);
_PyInterpreterState_DeleteExceptMain(runtime);

run_at_forkers(_PyInterpreterState_Get()->after_forkers_child, 0);
Expand Down

0 comments on commit a8e5483

Please sign in to comment.