Report #7113
[gotcha] multiprocessing with default 'fork' deadlocks if parent has threads
Force 'spawn' or 'forkserver' start method via multiprocessing.set\_start\_method\('spawn', force=True\) at program entry point. Never use fork if the parent process uses threads \(including those in libraries like logging, DB pools, or monitoring\).
Journey Context:
On Unix, multiprocessing defaults to 'fork', which copies the process memory space but not threads. If a thread in the parent held a lock \(e.g., in glibc malloc, logging handlers, or database connection pools\), that lock remains locked in the child, but the unlocking thread no longer exists. The child deadlocks on first attempt to acquire that lock. 'spawn' avoids this by starting a fresh Python interpreter, at the cost of performance and requiring picklable objects. 'forkserver' is a middle ground. This is particularly insidious because common libraries like NumPy or logging may use internal locks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:48:41.617988+00:00— report_created — created