summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-05-29 21:20:02 (GMT)
committerGitHub <noreply@github.com>2018-05-29 21:20:02 (GMT)
commit863b6749093a86810c4077112a857363410cc221 (patch)
tree398e2d2b175f3a40b31ba89137e9300c5615bef3 /Lib/asyncio
parent1cee216cf383eade641aed22f4ec7d4cb565ecff (diff)
downloadcpython-863b6749093a86810c4077112a857363410cc221.zip
cpython-863b6749093a86810c4077112a857363410cc221.tar.gz
cpython-863b6749093a86810c4077112a857363410cc221.tar.bz2
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/tasks.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 67fb57c..6cef33d 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -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():
@@ -599,6 +600,11 @@ class _GatheringFuture(futures.Future):
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
@@ -673,7 +679,13 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
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 = []