Report #53993
[gotcha] Multiprocessing defaults to fork on Linux and spawn on macOS causing pickling failures and resource leaks
Explicitly set start method to 'spawn' via multiprocessing.set\_start\_method\('spawn'\) in the main guard for cross-platform safety, or ensure all resources are initialized post-fork and never use threads with fork
Journey Context:
On Linux, multiprocessing defaults to 'fork', which copies the memory space including file descriptors but is unsafe if threads exist \(can deadlock\). On macOS and Windows, 'spawn' is default, which requires the main module to be importable and pickles the target function. Code working on Linux often fails on macOS with 'AttributeError: Can't pickle local object' or hangs without the \`if \_\_name\_\_ == '\_\_main\_\_':\` guard. Conversely, fork can leak file descriptors into children or interact badly with asyncio locks. The safest fix is to standardize on 'spawn' everywhere, accepting the slower startup and pickling requirements.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T21:07:31.335122+00:00— report_created — created