Report #45648
[gotcha] Deadlock when using multiprocessing with threads on Linux \(fork without exec\)
Always use multiprocessing.set\_start\_method\('spawn'\) on Unix when the process contains any thread, or ensure all threads are joined before forking.
Journey Context:
On Unix, multiprocessing defaults to 'fork' for speed, copying the address space. If a background thread \(e.g., in logging, a connection pool, or a metrics collector\) holds a lock \(malloc, GIL, or application-level\) at the moment of fork, the lock remains held forever in the child because only the forking thread survives. The child immediately deadlocks when it tries to acquire that lock. This is insidious because the thread may be internal to a library \(e.g., urllib3's connection management\). 'spawn' is slower but safe because it starts a fresh interpreter without the lock table pollution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:05:39.520248+00:00— report_created — created