{
  "id": 20997849,
  "title": "ThreadPoolExecutor result(timeout=1) Left 4 Calls Running",
  "url": "https://urgent.news/2026/11/21/threadpoolexecutor-result-timeout-1-left-4-calls-running",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-21T05:02:54.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/acemeridian/threadpoolexecutor-resulttimeout1-left-4-calls-running-4d8d"
  },
  "original_language": "en",
  "account": "The ThreadPoolExecutor result(timeout=1) function raised a TimeoutError after one second, but the associated thread continued to execute the call all the way through, without stopping. The call to the cancel() method returned False, indicating that even though the timeout occurred, the work was not actually halted. This occurs because Python does not have a built-in mechanism for terminating a thread once it has begun execution. The same issue arises when using asyncio.wait_for(to_thread(...), timeout=1), where the async function continues to run in the background after the timeout has been reached. The primary cost of this behavior is that when a pool of workers is fully occupied, any subsequent calls must wait in the queue until a worker becomes available, leading to increased latency. This behavior is consistent across both ThreadPoolExecutor and asyncio implementations. To prevent this issue, the recommended solution is to execute the slow tool function in a separate process, which can then be terminated with a timeout. Alternatively, the individual call can include its own internal timeout, such as using a timeout parameter in the HTTP client or an asyncio.timeout context manager. This approach ensures that the tool function stops running if it takes too long, avoiding unnecessary resources being consumed by the pool of workers.",
  "summary": "future.result(timeout=1) raises TimeoutError after one second, but the thread keeps running the call to the end, and future.cancel() returns False because the work already started; if a tool call must really stop, run it in a child process and terminate that process on timeout. In my test, four agent tool calls that each \"timed out\" after 1 s all ran their full 5 s, and the next 0.1 s call on the…",
  "key_points": [
    "ThreadPoolExecutor result(timeout=1) raises TimeoutError after 1 second",
    "Associated thread continues running call after timeout",
    "Recommended solution: execute function in separate process or include internal timeout"
  ],
  "editors_take": "The inability to terminate threads after a timeout forces developers to use separate processes or internal timeouts to prevent stalled workers from exhausting pool resources and increasing latency.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}