blob: e49577a203e8fb360952b9694b35010aec11f2ff [file] [log] [blame]
Yury Selivanov7c7605f2018-09-11 09:54:40 -07001.. currentmodule:: asyncio
2
3
Yury Selivanov7372c3b2018-09-14 15:11:24 -07004.. _asyncio-exceptions:
5
Yury Selivanov7c7605f2018-09-11 09:54:40 -07006==========
7Exceptions
8==========
9
10
11.. exception:: TimeoutError
12
13 The operation has exceeded the given deadline.
14
Yury Selivanov7372c3b2018-09-14 15:11:24 -070015 .. important::
Yury Selivanov7c7605f2018-09-11 09:54:40 -070016 This exception is different from the builtin :exc:`TimeoutError`
17 exception.
18
19
20.. exception:: CancelledError
21
22 The operation has been cancelled.
23
Carol Willinga3c8ba72018-09-13 16:14:41 -070024 This exception can be caught to perform custom operations
Yury Selivanov7c7605f2018-09-11 09:54:40 -070025 when asyncio Tasks are cancelled. In almost all situations the
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040026 exception must be re-raised.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070027
Yury Selivanov7372c3b2018-09-14 15:11:24 -070028 .. important::
Carol Willinga3c8ba72018-09-13 16:14:41 -070029
Yury Selivanov7c7605f2018-09-11 09:54:40 -070030 This exception is a subclass of :exc:`Exception`, so it can be
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040031 accidentally suppressed by an overly broad ``try..except`` block::
Yury Selivanov7c7605f2018-09-11 09:54:40 -070032
33 try:
34 await operation
35 except Exception:
36 # The cancellation is broken because the *except* block
37 # suppresses the CancelledError exception.
38 log.log('an error has occurred')
39
40 Instead, the following pattern should be used::
41
42 try:
43 await operation
44 except asyncio.CancelledError:
45 raise
46 except Exception:
47 log.log('an error has occurred')
48
49
50.. exception:: InvalidStateError
51
52 Invalid internal state of :class:`Task` or :class:`Future`.
53
54 Can be raised in situations like setting a result value for a
55 *Future* object that already has a result value set.
56
57
58.. exception:: SendfileNotAvailableError
59
Carol Willinga3c8ba72018-09-13 16:14:41 -070060 The "sendfile" syscall is not available for the given
Yury Selivanov7c7605f2018-09-11 09:54:40 -070061 socket or file type.
62
63 A subclass of :exc:`RuntimeError`.
64
65
66.. exception:: IncompleteReadError
67
Andre Delfino11205b82019-03-10 08:02:17 -030068 The requested read operation did not complete fully.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070069
Andre Delfino11205b82019-03-10 08:02:17 -030070 Raised by the :ref:`asyncio stream APIs<asyncio-streams>`.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070071
Andre Delfino11205b82019-03-10 08:02:17 -030072 This exception is a subclass of :exc:`EOFError`.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070073
74 .. attribute:: expected
75
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040076 The total number (:class:`int`) of expected bytes.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070077
78 .. attribute:: partial
79
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040080 A string of :class:`bytes` read before the end of stream was reached.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070081
82
83.. exception:: LimitOverrunError
84
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040085 Reached the buffer size limit while looking for a separator.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070086
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040087 Raised by the :ref:`asyncio stream APIs <asyncio-streams>`.
Yury Selivanov7c7605f2018-09-11 09:54:40 -070088
89 .. attribute:: consumed
90
Elvis Pranskevichus1fa2ec42018-09-17 19:16:44 -040091 The total number of to be consumed bytes.