summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/tasks.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-02 15:41:12 (GMT)
committerGitHub <noreply@github.com>2023-10-02 15:41:12 (GMT)
commitdd67e59bb195cac4a4d9fdc05eca217cd1918f96 (patch)
treec8779dcf73a0a2e244270d60a0bd08408d609f6b /Lib/asyncio/tasks.py
parent73ec1e7c219ea116521bd1024d23b352625966f0 (diff)
downloadcpython-dd67e59bb195cac4a4d9fdc05eca217cd1918f96.zip
cpython-dd67e59bb195cac4a4d9fdc05eca217cd1918f96.tar.gz
cpython-dd67e59bb195cac4a4d9fdc05eca217cd1918f96.tar.bz2
[3.12] gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (#109992)
gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (cherry picked from commit 45cf5b0c69bb5c51f33fc681d90c45147e311ddf) Co-authored-by: Kristján Valur Jónsson <sweskman@gmail.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r--Lib/asyncio/tasks.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 152c9f8..65f2a6e 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -86,15 +86,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
"""A coroutine wrapped in a Future."""
# An important invariant maintained while a Task not done:
+ # _fut_waiter is either None or a Future. The Future
+ # can be either done() or not done().
+ # The task can be in any of 3 states:
#
- # - Either _fut_waiter is None, and _step() is scheduled;
- # - or _fut_waiter is some Future, and _step() is *not* scheduled.
+ # - 1: _fut_waiter is not None and not _fut_waiter.done():
+ # __step() is *not* scheduled and the Task is waiting for _fut_waiter.
+ # - 2: (_fut_waiter is None or _fut_waiter.done()) and __step() is scheduled:
+ # the Task is waiting for __step() to be executed.
+ # - 3: _fut_waiter is None and __step() is *not* scheduled:
+ # the Task is currently executing (in __step()).
#
- # The only transition from the latter to the former is through
- # _wakeup(). When _fut_waiter is not None, one of its callbacks
- # must be _wakeup().
-
- # If False, don't log a message if the task is destroyed whereas its
+ # * In state 1, one of the callbacks of __fut_waiter must be __wakeup().
+ # * The transition from 1 to 2 happens when _fut_waiter becomes done(),
+ # as it schedules __wakeup() to be called (which calls __step() so
+ # we way that __step() is scheduled).
+ # * It transitions from 2 to 3 when __step() is executed, and it clears
+ # _fut_waiter to None.
+
+ # If False, don't log a message if the task is destroyed while its
# status is still pending
_log_destroy_pending = True