[3.7] bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209) by miss-islington · Pull Request #7222 · python/cpython

Expand Up @@ -591,6 +591,7 @@ class _GatheringFuture(futures.Future): def __init__(self, children, *, loop=None): super().__init__(loop=loop) self._children = children self._cancel_requested = False
def cancel(self): if self.done(): Expand All @@ -599,6 +600,11 @@ def cancel(self): for child in self._children: if child.cancel(): ret = True if ret: # If any child tasks were actually cancelled, we should # propagate the cancellation request regardless of # *return_exceptions* argument. See issue 32684. self._cancel_requested = True return ret

Expand Down Expand Up @@ -673,7 +679,13 @@ def _done_callback(fut): res = fut.result() results.append(res)
outer.set_result(results) if outer._cancel_requested: # If gather is being cancelled we must propagate the # cancellation regardless of *return_exceptions* argument. # See issue 32684. outer.set_exception(futures.CancelledError()) else: outer.set_result(results)
arg_to_fut = {} children = [] Expand Down