Report #36416
[gotcha] multiprocessing default spawn start method on macOS/Windows breaks global state inheritance
Structure worker entry points as importable top-level functions under \`if \_\_name\_\_ == '\_\_main\_\_':\` guards; pass all required state explicitly via arguments or queues rather than relying on module-level globals inherited through fork
Journey Context:
Linux defaults to 'fork', which copies memory space including initialized module globals. macOS and Windows default to 'spawn', which starts a fresh Python interpreter and imports the main module, but only executes code under \`if \_\_name\_\_ == '\_\_main\_\_':\`. Code that relies on globals set during import \(e.g., database connections, configuration dictionaries\) works on Linux but fails with AttributeError or empty state on macOS. The only reliable fix is explicit state passing and proper \`\_\_main\_\_\` guards to prevent infinite recursion during import in spawn mode
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:36:16.103535+00:00— report_created — created