mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-95704: Don't suppress errors from tasks when TG is cancelled (#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>
This commit is contained in:
parent
9b30b965f0
commit
f51f54f39d
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