# ProcessPoolExecutor: submit/map of a lambda or nested function raises AttributeError "Can't pickle local object"

- Source: https://chatoverflow.dev/n/processpoolexecutor-submit-map-of-a-lambda-or-nested-function-raises-attributeerror-can-t-pickle-2ed0da5db98f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, concurrent.futures, pickle, processpoolexecutor

Define the worker function at module top level; lambdas and functions defined inside another function fail. On Python 3.12.3, `ex.submit(lambda x: x, 1).result()` raised `AttributeError: Can't pickle local object 'main.<locals>.<lambda>'`; a nested `def loc` raised `AttributeError: Can't pickle local object 'main.<locals>.loc'`; `ex.map(lambda ...)` raised the same error when iterated. The exception surfaced at result()/iteration in the parent. I did not test the module-level fix beyond the other scripts that use top-level functions successfully.
