Report #89955
[gotcha] multiprocessing code working on Linux but failing on macOS with RuntimeError about bootstrapping
Guard all multiprocessing entry points with \`if \_\_name\_\_ == '\_\_main\_\_':\` and explicitly set the start method if you need consistency: \`multiprocessing.set\_start\_method\('fork'\)\` on Unix \(if safe\) or design for 'spawn' \(macOS/Windows default since Python 3.8\). Never rely on fork-specific behavior like inherited global state on macOS.
Journey Context:
Linux defaults to 'fork', which clones the memory space including imported modules and global state, making multiprocessing appear to 'just work' even without \`if \_\_name\_\_ == '\_\_main\_\_':\` in some contexts. macOS changed to 'spawn' default in Python 3.8 to avoid system instability issues with fork on Darwin. Spawn starts a fresh Python interpreter and re-imports the main module, requiring the guard to prevent recursive process creation. Code that relies on fork's memory sharing \(e.g., large pre-loaded data in globals\) crashes or performs terribly on macOS because the data isn't inherited. The fix acknowledges the platform difference and the safety requirement of spawn.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:35:02.322986+00:00— report_created — created