Report #6309
[gotcha] Global variables or imported modules not available in multiprocessing child process on macOS after Python 3.8
Explicitly set \`multiprocessing.set\_start\_method\('fork'\)\` only if your code is fork-safe \(no threads, no Objective-C frameworks\), otherwise refactor to use \`if \_\_name\_\_ == '\_\_main\_\_':\` guards and pass necessary data via arguments or shared memory, accepting that 'spawn' requires serializable data.
Journey Context:
POSIX allows fork \(copy-on-write\) or spawn \(fresh interpreter\). Linux defaults to fork; macOS changed to spawn in 3.8 because fork is unsafe with the system Objective-C runtime \(crash risk\). Spawn starts a blank interpreter and re-imports the main module, which means: \(1\) \`if \_\_name\_\_ == '\_\_main\_\_':\` is mandatory to avoid infinite recursion, \(2\) global variables from the parent are not copied \(unlike fork\), \(3\) imported modules are reloaded \(new class identity issues\). Fork is faster and shares memory but risks deadlocks if threads existed pre-fork. The tradeoff is safety \(spawn\) vs performance/state sharing \(fork\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:44:36.507380+00:00— report_created — created