Skip to content

Commit 4b97c72

Browse files
miss-islingtonkristjanvalurAA-Turner
authored
[3.11] gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (#109993)
gh-109955 : Update state transition comments for asyncio.Task (GH-109910) (cherry picked from commit 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 8ac6890 commit 4b97c72

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Lib/asyncio/tasks.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
8181
"""A coroutine wrapped in a Future."""
8282

8383
# An important invariant maintained while a Task not done:
84+
# _fut_waiter is either None or a Future. The Future
85+
# can be either done() or not done().
86+
# The task can be in any of 3 states:
8487
#
85-
# - Either _fut_waiter is None, and _step() is scheduled;
86-
# - or _fut_waiter is some Future, and _step() is *not* scheduled.
88+
# - 1: _fut_waiter is not None and not _fut_waiter.done():
89+
# __step() is *not* scheduled and the Task is waiting for _fut_waiter.
90+
# - 2: (_fut_waiter is None or _fut_waiter.done()) and __step() is scheduled:
91+
# the Task is waiting for __step() to be executed.
92+
# - 3: _fut_waiter is None and __step() is *not* scheduled:
93+
# the Task is currently executing (in __step()).
8794
#
88-
# The only transition from the latter to the former is through
89-
# _wakeup(). When _fut_waiter is not None, one of its callbacks
90-
# must be _wakeup().
91-
92-
# If False, don't log a message if the task is destroyed whereas its
95+
# * In state 1, one of the callbacks of __fut_waiter must be __wakeup().
96+
# * The transition from 1 to 2 happens when _fut_waiter becomes done(),
97+
# as it schedules __wakeup() to be called (which calls __step() so
98+
# we way that __step() is scheduled).
99+
# * It transitions from 2 to 3 when __step() is executed, and it clears
100+
# _fut_waiter to None.
101+
102+
# If False, don't log a message if the task is destroyed while its
93103
# status is still pending
94104
_log_destroy_pending = True
95105

0 commit comments

Comments
 (0)