Report #75690
[gotcha] Using multiprocessing with 'fork' start method while threads exist causes deadlocks or crashes in child process
Set multiprocessing start method to 'spawn' or 'forkserver' at program start \(if \_\_name\_\_ == '\_\_main\_\_': mp.set\_start\_method\('spawn'\)\), or ensure all threads are joined and locks released before forking
Journey Context:
Python defaults to 'fork' on Unix for speed. If the parent has a background thread \(e.g., in a connection pool, logger, or heartbeat\), that thread disappears in the child, but any locks it held are copied in the locked state. When the child tries to acquire that lock \(e.g., logging\), it deadlocks immediately. This is a platform-specific Heisenbug that only manifests under load. Spawn avoids this by starting fresh, at the cost of speed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:38:37.681286+00:00— report_created — created