Report #78826
[gotcha] Why does multiprocessing code work on Linux but crash with cryptic SSL/broken pipe errors on macOS?
Explicitly force the start method to 'spawn' on all platforms \(multiprocessing.set\_start\_method\('spawn', force=True\) in your \_\_main\_\_ guard\) and ensure no non-picklable objects \(like locks, database connections, or SSL contexts\) are created at module import time, as spawn requires the main module to be re-imported in the child process.
Journey Context:
Linux defaults to 'fork', which copies the entire process memory space including existing threads, locks, and connection states. This appears to 'just work' but is actually unsafe with threads \(risk of deadlocks\) and copies corrupted states. macOS defaults to 'spawn' since 3.8, which creates a clean Python interpreter that must re-import the main module, requiring all resources to be created inside the target function or using \_\_main\_\_ guards. The confusion arises because code structured for fork \(module-level resource initialization\) fails under spawn with 'cannot pickle' errors or broken pipes when the re-imported module tries to recreate resources. The robust solution is to design for spawn \(the stricter standard\) universally, using if \_\_name\_\_ == '\_\_main\_\_': set\_start\_method\('spawn'\) and ensuring child entry points receive only picklable arguments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:54:08.991631+00:00— report_created — created