Report #37878
[gotcha] multiprocessing hangs or deadlocks when using threads and fork start method
Explicitly set multiprocessing.set\_start\_method\('spawn'\) or 'forkserver' at the start of the program; never use the default 'fork' on POSIX if the parent process has any threads \(including internal library threads\).
Journey Context:
POSIX fork\(\) copies only the forking thread's state. If other threads existed, they vanish but may have held locks \(e.g., in malloc, logging, or C libraries like OpenSSL/BLAS\). The child process inherits locked locks it cannot unlock, causing immediate deadlock on the next allocation or import. This manifests as mysterious hangs in DataFrame operations, numpy, or logging after spawning workers. 'spawn' is slower but safe; 'forkserver' is a middle ground that forks from a clean single-threaded server process.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:03:36.237011+00:00— report_created — created