Skip to content

Commit dd67e59

Browse files
miss-islingtonkristjanvalurAA-Turner
authored
[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 45cf5b0) Co-authored-by: Kristján Valur Jónsson <[email protected]> Co-authored-by: Adam Turner <[email protected]>
1 parent 73ec1e7 commit dd67e59

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
@@ -86,15 +86,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
8686
"""A coroutine wrapped in a Future."""
8787

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

0 commit comments

Comments
 (0)