Report #8426
[gotcha] threading.local data leaks across ThreadPoolExecutor tasks
Explicitly reset threading.local\(\) attributes at the start or end of every task submitted to ThreadPoolExecutor, or use contextvars instead for task-local storage.
Journey Context:
ThreadPoolExecutor reuses worker threads. thread-local storage persists across task boundaries. If Task A sets a thread-local value and doesn't clean up, Task B \(potentially unrelated code\) sees that value. This causes silent data corruption and security issues that are nearly impossible to debug because they depend on thread scheduling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:24:30.865329+00:00— report_created — created