diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-08-17 17:04:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 17:04:59 (GMT) |
commit | 36c114ab11d478c9ede246035606c12fc080e6ff (patch) | |
tree | 1ea0cda50707031ab99942c2adfd59242d0a1e0d /Lib/asyncio | |
parent | 2bb363cfcd7563fdd29ac93563f95b8a5205b008 (diff) | |
download | cpython-36c114ab11d478c9ede246035606c12fc080e6ff.zip cpython-36c114ab11d478c9ede246035606c12fc080e6ff.tar.gz cpython-36c114ab11d478c9ede246035606c12fc080e6ff.tar.bz2 |
GH-95704: Don't suppress errors from tasks when TG is cancelled (GH-95761)
When a task catches CancelledError and raises some other error,
the other error should not silently be suppressed.
Any scenario where a task crashes in cleanup upon cancellation
will now result in an ExceptionGroup wrapping the crash(es)
instead of propagating CancelledError and ignoring the side errors.
NOTE: This represents a change in behavior (hence the need to
change several tests). But it is only an edge case.
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
(cherry picked from commit f51f54f39d384da63be622bcdc9cf4cfb43bad3d)
Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/taskgroups.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/asyncio/taskgroups.py b/Lib/asyncio/taskgroups.py index 9be4838..5d5e2a8 100644 --- a/Lib/asyncio/taskgroups.py +++ b/Lib/asyncio/taskgroups.py @@ -116,10 +116,9 @@ class TaskGroup: if self._base_error is not None: raise self._base_error - if propagate_cancellation_error is not None: - # The wrapping task was cancelled; since we're done with - # closing all child tasks, just propagate the cancellation - # request now. + # Propagate CancelledError if there is one, except if there + # are other errors -- those have priority. + if propagate_cancellation_error and not self._errors: raise propagate_cancellation_error if et is not None and et is not exceptions.CancelledError: |