]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-37703: improve asyncio.gather documentation regarding cancellation (GH-15312)
authorVinay Sharma <vinay04sharma@icloud.com>
Mon, 20 Jul 2020 08:42:57 +0000 (14:12 +0530)
committerGitHub <noreply@github.com>
Mon, 20 Jul 2020 08:42:57 +0000 (01:42 -0700)
These changes updates the doc to comprehensively mention the behaviour of gather.cancel()

Automerge-Triggered-By: @asvetlov
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 bac99b795044494e264599fbdcd7a613dcad7c39..99f012540d989b64ead8add7dbcb362463e657a6 100644 (file)
@@ -387,6 +387,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 5e0692ef7778a32cc254004a319a162ce0090fac..c37f0e1387980c069db56017bd3284970c9f24d7 100644 (file)
@@ -729,6 +729,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()