blob: 7f3ed857943dae4f67a963699a811b5db83e06e4 [file] [log] [blame]
Yury Selivanov7c7605f2018-09-11 09:54:40 -07001.. currentmodule:: asyncio
2
3
4==========
5Exceptions
6==========
7
8
9.. exception:: TimeoutError
10
11 The operation has exceeded the given deadline.
12
13 .. note::
14 This exception is different from the builtin :exc:`TimeoutError`
15 exception.
16
17
18.. exception:: CancelledError
19
20 The operation has been cancelled.
21
Carol Willinga3c8ba72018-09-13 16:14:41 -070022 This exception can be caught to perform custom operations
Yury Selivanov7c7605f2018-09-11 09:54:40 -070023 when asyncio Tasks are cancelled. In almost all situations the
24 exception must always be re-raised.
25
26 .. note::
Carol Willinga3c8ba72018-09-13 16:14:41 -070027
Yury Selivanov7c7605f2018-09-11 09:54:40 -070028 This exception is a subclass of :exc:`Exception`, so it can be
29 accidentally suppressed by ``try..except`` block::
30
31 try:
32 await operation
33 except Exception:
34 # The cancellation is broken because the *except* block
35 # suppresses the CancelledError exception.
36 log.log('an error has occurred')
37
38 Instead, the following pattern should be used::
39
40 try:
41 await operation
42 except asyncio.CancelledError:
43 raise
44 except Exception:
45 log.log('an error has occurred')
46
47
48.. exception:: InvalidStateError
49
50 Invalid internal state of :class:`Task` or :class:`Future`.
51
52 Can be raised in situations like setting a result value for a
53 *Future* object that already has a result value set.
54
55
56.. exception:: SendfileNotAvailableError
57
Carol Willinga3c8ba72018-09-13 16:14:41 -070058 The "sendfile" syscall is not available for the given
Yury Selivanov7c7605f2018-09-11 09:54:40 -070059 socket or file type.
60
61 A subclass of :exc:`RuntimeError`.
62
63
64.. exception:: IncompleteReadError
65
66 Incomplete read error.
67
68 Raised by :ref:`asyncio streams <asyncio-streams>` APIs.
69
70 This exception is a subclass of :exc:`EOFError`.
71
72 .. attribute:: expected
73
74 Total number (:class:`int`) of expected bytes.
75
76 .. attribute:: partial
77
78 Read :class:`bytes` string before the end of stream was reached.
79
80
81.. exception:: LimitOverrunError
82
83 Reached the buffer limit while looking for a separator.
84
85 Raised by :ref:`asyncio streams <asyncio-streams>` APIs.
86
87 .. attribute:: consumed
88
89 Total number of to be consumed bytes.