Python Glossary Русский

Python 3.3+Exceptionsexception

InterruptedError

built-in exceptions

A system call was interrupted by a signal (a subclass of OSError). Modern Python usually retries such calls automatically.

Syntax

raise InterruptedError

Since PEP 475 (Python 3.5) the interpreter retries system calls interrupted by a signal on its own, so the old catch-and-retry loop is obsolete and you will rarely see this exception in ordinary code. Do not confuse it with Ctrl+C, which produces KeyboardInterrupt instead. Being a subclass of OSError, it is picked up by a plain except OSError along with other I/O failures.

Examples

try:
    raise InterruptedError
except InterruptedError as e:
    print(type(e).__name__)   # → InterruptedError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy