Atle Solbakken added the comment:
By "manually" clearing/deleting any interpreter states from non-main thread
states prior to running (PyOS_AfterForkChild()), the deadlock does not occur.
// With tstate_orig being a PyThreadState which is not main:
PyInterpreterState *istate = t
New submission from Atle Solbakken :
In _PyInterpreterState_DeleteExceptMain() aqcuires lock with
HEAD_LOCK(runtime). With the lock still held and if a interpreter state is to
be cleared, _PyInterpreterState_Clear() is called. HEAD_LOCK(runtime) is then
called again (from within Clear