Skip to content

Commit 1498a45

Browse files
committed
bpo-37703: improve asyncio.gather documentation regarding cancellation
1 parent f3cb68f commit 1498a45

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Doc/library/asyncio-task.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ Running Tasks Concurrently
327327

328328
If ``gather()`` is *cancelled*, all submitted awaitables
329329
(that have not completed yet) are also *cancelled*.
330+
**Note:** Cancelling gather() after it has been marked done
331+
won't cancel any submitted awaitables. For instance, gather
332+
can be marked done after propagating an exception to the caller,
333+
therefore, calling ``gather.cancel()`` after catching an exception
334+
(raised by one of the awaitables) from gather won't cancel any
335+
other awaitables.
330336

331337
If any Task or Future from the *aws* sequence is *cancelled*, it is
332338
treated as if it raised :exc:`CancelledError` -- the ``gather()``

Lib/asyncio/tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
729729
the outer Future is *not* cancelled in this case. (This is to
730730
prevent the cancellation of one child to cause other children to
731731
be cancelled.)
732+
**Note:** Cancelling gather() after it has been marked done
733+
won't cancel any submitted awaitables. For instance, gather
734+
can be marked done after propagating an exception to the caller,
735+
therefore, calling ``gather.cancel()`` after catching an exception
736+
(raised by one of the awaitables) from gather won't cancel any
737+
other awaitables.
732738
"""
733739
if not coros_or_futures:
734740
if loop is None:

0 commit comments

Comments
 (0)