Report #8428
[gotcha] pickle fails to unpickle lambdas or \_\_main\_\_ functions
Never pickle lambdas, nested functions, or functions defined in \_\_main\_\_. Ensure all pickled callables are importable top-level names in a real module. Use dill or cloudpickle only if you accept the security/fragility tradeoffs.
Journey Context:
Pickle stores references by name, not code. Lambdas and nested functions have no persistent import path. When unpickling, pickle tries to import the name; if it's \_\_main\_\_ or a closure, it fails with AttributeError or UnpicklingError. This breaks when moving from Jupyter/notebooks to production or using multiprocessing with spawn.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:24:31.299023+00:00— report_created — created