bpo-37651: Document CancelledError is now a subclass of BaseException (GH-15950)
https://bugs.python.org/issue37651
Automerge-Triggered-By: @1st1
(cherry picked from commit 7b69069e9a
)
Co-authored-by: Xtreak <tir.karthi@gmail.com>
This commit is contained in:
parent
aa527174f0
commit
e784bb7c6b
|
@ -25,26 +25,9 @@ Exceptions
|
||||||
when asyncio Tasks are cancelled. In almost all situations the
|
when asyncio Tasks are cancelled. In almost all situations the
|
||||||
exception must be re-raised.
|
exception must be re-raised.
|
||||||
|
|
||||||
.. important::
|
.. versionchanged:: 3.8
|
||||||
|
|
||||||
This exception is a subclass of :exc:`Exception`, so it can be
|
:exc:`CancelledError` is now a subclass of :class:`BaseException`.
|
||||||
accidentally suppressed by an overly broad ``try..except`` block::
|
|
||||||
|
|
||||||
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
|
.. exception:: InvalidStateError
|
||||||
|
|
Loading…
Reference in New Issue