You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
concurrent.futures: Executor.map cancels the remaining calls when the callable raises TimeoutError #155852
gh-108518 documented that if a call raises, :meth:Executor.map no longer
cancels the remaining calls and iteration can continue. That holds for every
exception except :exc:TimeoutError, which still aborts and cancels the rest.
fromconcurrent.futuresimportThreadPoolExecutordeff(x):
ifx==2:
raiseTimeoutError# e.g. a socket.timeout from one network callreturnxwithThreadPoolExecutor() asex:
it=ex.map(f, [1, 2, 3, 4])
print(next(it)) # 1try: next(it) # raises TimeoutError for x=2exceptTimeoutError: passprint(list(it)) # [] -- 3 and 4 were cancelled
With any other exception (e.g. ValueError) the last line prints [3, 4]. socket.timeout and asyncio.TimeoutError are aliases of
:exc:TimeoutError, so a single timed-out call in a mapped batch silently
drops all remaining work. ProcessPoolExecutor is unaffected.
The cause is in _result_or_cancel: a TimeoutError from the callable is
indistinguishable by type from the map(timeout=...) wait timeout, so it is
re-raised instead of being returned like other exceptions.
Activity
picnixz commentedon Aug 15, 2026
cc @serhiy-storchaka
gh-155852: Do not cancel remaining Executor.map calls on a callable's…