Report #92228
[gotcha] ProcessPoolExecutor fails with AttributeError or PicklingError on macOS or when using interactively defined functions
Use \`if \_\_name\_\_ == '\_\_main\_\_':\` guard when spawning processes; define worker functions at module level not in lambdas or interactively; on macOS use \`multiprocessing.set\_start\_method\('fork', force=True\)\` only if you understand the risks, or refactor to use \`concurrent.futures.ThreadPoolExecutor\` with \`asyncio\` for I/O bound work
Journey Context:
Python 3.8 changed macOS default from 'fork' to 'spawn' to avoid CVE-2018-4190 and deadlocks with CoreFoundation. Spawn requires pickling functions, which fails for lambdas, local functions, or \`\_\_main\_\_\` methods without the guard. Many developers hit this when moving Linux code to macOS. The \`max\_tasks\_per\_child\` \(3.11\+\) helps with memory leaks but requires understanding the spawn overhead. The fix is architectural: spawn-compatible code structure or using threads for I/O.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T13:23:48.655610+00:00— report_created — created