Report #11270
[gotcha] multiprocessing hangs or infinitely recurses on macOS/Windows without main guard
Always wrap multiprocessing entry points in \`if \_\_name\_\_ == '\_\_main\_\_':\` when using spawn \(default on macOS/Windows\); use forkserver or fork on Linux only if main guard is impossible.
Journey Context:
The spawn start method starts a fresh Python interpreter that re-imports the main module to pickle/unpickle state. Without the guard, the child process re-executes the spawning code, creating infinite recursion. Fork inherits memory state so it doesn't re-run main, but fork is unsafe with threads and unavailable on Windows; macOS changed default to spawn in 3.8 to avoid fork safety issues.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:53:16.842555+00:00— report_created — created