mirror of
https://github.com/python/cpython.git
synced 2025-09-10 18:58:35 +00:00
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 f51f54f39d
)
Co-authored-by: Guido van Rossum <guido@python.org>
This commit is contained in:
parent
2bb363cfcd
commit
36c114ab11
3 changed files with 35 additions and 28 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue