]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-37703: improve asyncio.gather documentation regarding cancellation (GH-15312)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Jul 2020 09:00:51 +0000 (02:00 -0700)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 09:00:51 +0000 (02:00 -0700)
These changes updates the doc to comprehensively mention the behaviour of gather.cancel()

Automerge-Triggered-By: @asvetlov
(cherry picked from commit d42528a3a2c7d79fd2e6c9f2a02f3ce12d44c8cc)

Co-authored-by: Vinay Sharma <vinay04sharma@icloud.com>
Doc/library/asyncio-task.rst
Lib/asyncio/tasks.py
Misc/NEWS.d/next/Documentation/2019-08-16-20-25-42.bpo-37703.Qm_l_H.rst [new file with mode: 0644]

index 00ce5d4b72bdd34a403fb247a904be6e0a792c85..c96dde2dde9254f7b4db1ad2ee9790169d3d16e9 100644 (file)
@@ -385,6 +385,14 @@ Running Tasks Concurrently
       #     Task C: Compute factorial(4)...
       #     Task C: factorial(4) = 24
 
+   .. note::
+      If *return_exceptions* is False, 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.
+
    .. versionchanged:: 3.7
       If the *gather* itself is cancelled, the cancellation is
       propagated regardless of *return_exceptions*.
index 38d982716d46ad1b5b37c8d6b03185d0274eec31..66e81f9200a36d8478790bb0fe8f8bda2852fb46 100644 (file)
@@ -736,6 +736,13 @@ 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.)
+
+    If *return_exceptions* is False, 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:
diff --git a/Misc/NEWS.d/next/Documentation/2019-08-16-20-25-42.bpo-37703.Qm_l_H.rst b/Misc/NEWS.d/next/Documentation/2019-08-16-20-25-42.bpo-37703.Qm_l_H.rst
new file mode 100644 (file)
index 0000000..a1a1c35
--- /dev/null
@@ -0,0 +1,2 @@
+Updated Documentation to comprehensively elaborate on the behaviour of
+gather.cancel()