Report #66734
[gotcha] Multiprocessing code works on Linux but fails on Windows with PicklingError for local functions
Explicitly set multiprocessing.set\_start\_method\('spawn'\) during application initialization \(guard with if \_\_name\_\_ == '\_\_main\_\_':\) and ensure all target functions are pickleable \(top-level module functions, not lambdas or local functions\). Test on Windows early in development.
Journey Context:
Unix systems default to 'fork', which copies the process memory space including function pointers, allowing local functions and lambdas to work by reference. Windows uses 'spawn', which starts a fresh Python interpreter and requires pickling the target function to send it to the new process. Local functions and lambdas are not pickleable by default. This causes code that works perfectly on Linux/Mac to crash immediately on Windows with obscure PicklingError. The fix is to explicitly use 'spawn' \(for consistency across platforms\) and refactor to use top-level functions or callable classes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:29:37.185092+00:00— report_created — created