From c993055eedd779ddb6e7587a3d20db7274438213 Mon Sep 17 00:00:00 2001 From: Vinay Sharma Date: Fri, 16 Aug 2019 13:19:53 +0530 Subject: [PATCH] bpo-37703: improve asyncio.gather documentation regarding cancellation --- Doc/library/asyncio-task.rst | 6 ++++++ Lib/asyncio/tasks.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 1fcdcb985d..190d262731 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -327,6 +327,12 @@ Running Tasks Concurrently If ``gather()`` is *cancelled*, all submitted awaitables (that have not completed yet) are also *cancelled*. + **Note:** Cancelling gather() after it has been marked done + won't cancel any submitted awaitables. For instance, gather + can be marked done after propagating an exception to the caller, + therefore, calling ``gather.cancel()`` after catching an exception + (raised by one of the awaitables) from gather won't cancel any + other awaitables. If any Task or Future from the *aws* sequence is *cancelled*, it is treated as if it raised :exc:`CancelledError` -- the ``gather()`` diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index cd4832cfee..f6015460eb 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -729,6 +729,12 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False): the outer Future is *not* cancelled in this case. (This is to prevent the cancellation of one child to cause other children to be cancelled.) + **Note:** Cancelling gather() after it has been marked done + won't cancel any submitted awaitables. For instance, gather + can be marked done after propagating an exception to the caller, + therefore, calling ``gather.cancel()`` after catching an exception + (raised by one of the awaitables) from gather won't cancel any + other awaitables. """ if not coros_or_futures: if loop is None: -- 2.20.1 (Apple Git-117)