2018-09-11 13:54:40 -03:00
|
|
|
.. currentmodule:: asyncio
|
|
|
|
|
|
|
|
|
2018-09-14 19:11:24 -03:00
|
|
|
.. _asyncio-exceptions:
|
|
|
|
|
2018-09-11 13:54:40 -03:00
|
|
|
==========
|
|
|
|
Exceptions
|
|
|
|
==========
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: TimeoutError
|
|
|
|
|
|
|
|
The operation has exceeded the given deadline.
|
|
|
|
|
2018-09-14 19:11:24 -03:00
|
|
|
.. important::
|
2018-09-11 13:54:40 -03:00
|
|
|
This exception is different from the builtin :exc:`TimeoutError`
|
|
|
|
exception.
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: CancelledError
|
|
|
|
|
|
|
|
The operation has been cancelled.
|
|
|
|
|
2018-09-13 20:14:41 -03:00
|
|
|
This exception can be caught to perform custom operations
|
2018-09-11 13:54:40 -03:00
|
|
|
when asyncio Tasks are cancelled. In almost all situations the
|
2018-09-17 20:16:44 -03:00
|
|
|
exception must be re-raised.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
2018-09-14 19:11:24 -03:00
|
|
|
.. important::
|
2018-09-13 20:14:41 -03:00
|
|
|
|
2018-09-11 13:54:40 -03:00
|
|
|
This exception is a subclass of :exc:`Exception`, so it can be
|
2018-09-17 20:16:44 -03:00
|
|
|
accidentally suppressed by an overly broad ``try..except`` block::
|
2018-09-11 13:54:40 -03:00
|
|
|
|
|
|
|
try:
|
|
|
|
await operation
|
|
|
|
except Exception:
|
|
|
|
# The cancellation is broken because the *except* block
|
|
|
|
# suppresses the CancelledError exception.
|
|
|
|
log.log('an error has occurred')
|
|
|
|
|
|
|
|
Instead, the following pattern should be used::
|
|
|
|
|
|
|
|
try:
|
|
|
|
await operation
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
raise
|
|
|
|
except Exception:
|
|
|
|
log.log('an error has occurred')
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: InvalidStateError
|
|
|
|
|
|
|
|
Invalid internal state of :class:`Task` or :class:`Future`.
|
|
|
|
|
|
|
|
Can be raised in situations like setting a result value for a
|
|
|
|
*Future* object that already has a result value set.
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: SendfileNotAvailableError
|
|
|
|
|
2018-09-13 20:14:41 -03:00
|
|
|
The "sendfile" syscall is not available for the given
|
2018-09-11 13:54:40 -03:00
|
|
|
socket or file type.
|
|
|
|
|
|
|
|
A subclass of :exc:`RuntimeError`.
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: IncompleteReadError
|
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
The requested read operation did not complete fully.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
Raised by the :ref:`asyncio stream APIs<asyncio-streams>`.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
|
|
|
This exception is a subclass of :exc:`EOFError`.
|
|
|
|
|
|
|
|
.. attribute:: expected
|
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
The total number (:class:`int`) of expected bytes.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
|
|
|
.. attribute:: partial
|
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
A string of :class:`bytes` read before the end of stream was reached.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. exception:: LimitOverrunError
|
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
Reached the buffer size limit while looking for a separator.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
Raised by the :ref:`asyncio stream APIs <asyncio-streams>`.
|
2018-09-11 13:54:40 -03:00
|
|
|
|
|
|
|
.. attribute:: consumed
|
|
|
|
|
2018-09-17 20:16:44 -03:00
|
|
|
The total number of to be consumed bytes.
|