Report #28882
[gotcha] ThreadPoolExecutor thread-local state leaks between unrelated task submissions
Explicitly delete \`threading.local\(\)\` attributes in a \`finally\` block at the end of every task function submitted to the executor; never assume a fresh thread per task.
Journey Context:
ThreadPoolExecutor maintains a pool of worker threads that persist across task submissions to avoid creation overhead. \`threading.local\(\)\` is bound to the OS thread's lifetime, not the task's. When Task A sets \`local.x = 1\` and completes, the thread returns to the pool. If Task B is scheduled on that same thread, \`local.x\` remains \`1\`, causing silent state pollution and heisenbugs. Explicit cleanup or weakref finalizers are required because the executor does not reset thread state.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:52:25.941985+00:00— report_created — created