Report #56361
[gotcha] multiprocessing spawn start method causes infinite recursion or crashes without main guard
Always place multiprocessing execution logic inside if \_\_name\_\_ == '\_\_main\_\_': blocks; never define Pool/Process at module level or in imported scripts when using spawn.
Journey Context:
The 'spawn' method \(default on Windows/macOS, and available on Linux\) starts a fresh Python interpreter, which re-imports the main module. Without the guard, the child process re-executes the spawning code, creating another child, leading to a fork bomb or RuntimeError. Linux users developing on 'fork' \(default there\) often deploy to Linux servers where it works, then port to Windows/macOS and encounter mysterious crashes. The guard is non-obvious because it looks like boilerplate; many tutorials omit it for brevity, causing production failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:05:38.471016+00:00— report_created — created