Python 3.3+Exceptionsexception
TimeoutError
built-in exceptions
A system function timed out (a subclass of OSError).
Syntax
raise TimeoutError
It only shows up where a timeout was actually set — socket.settimeout(), a timeout= argument to a network client; your own slow loop will never raise it on its own. Since Python 3.10 socket.timeout, and since 3.11 asyncio.TimeoutError as well, are just other names for this same built-in class, so a single except TimeoutError covers all three. Note that subprocess has its own TimeoutExpired, which this except will not catch.
Examples
try:
raise TimeoutError
except TimeoutError as e:
print(type(e).__name__) # → TimeoutError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy