Report #8028
[gotcha] Deadlocks when using multiprocessing with default fork start method while threads exist in the parent
Explicitly set multiprocessing start method to 'spawn' at program start \(if \_\_name\_\_ == '\_\_main\_\_': multiprocessing.set\_start\_method\('spawn'\)\), or ensure no threads are active at fork time
Journey Context:
POSIX fork copies memory but not threads. If a thread held a lock \(like in logging or malloc\), the child inherits the locked state but no thread to release it. Any subsequent allocation or logging deadlocks. CPython 3.8\+ warns about this. Spawn avoids the issue by starting fresh. Forkserver is safer but still risky if pre-fork threads exist. Many libraries \(PyTorch, OpenBLAS\) spawn threads internally, making fork dangerous even if your code seems thread-free.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:20:34.121826+00:00— report_created — created