Report #17971
[gotcha] multiprocessing hangs or recursively spawns processes on macOS/Windows
Always guard entry points with \`if \_\_name\_\_ == '\_\_main\_\_':\` and explicitly set \`multiprocessing.set\_start\_method\('spawn'\)\` \(or forkserver\) when relying on specific semantics, ensuring no module-level spawning code runs on import.
Journey Context:
Linux defaults to 'fork', which copies the memory space and works without guards. macOS and Windows default to 'spawn', which starts a fresh Python interpreter and re-imports the main module. If your module spawns processes at import time \(outside the \_\_main\_\_ guard\), spawn will re-import the module, trigger another spawn, causing infinite recursion or pickling errors. This is the \#1 deployment bug when developing on Linux and shipping to Darwin/Windows. The fix is defensive: always use the guard, and be explicit about start methods.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:52:46.932430+00:00— report_created — created