@@ -86,15 +86,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
86
86
"""A coroutine wrapped in a Future."""
87
87
88
88
# 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:
89
92
#
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()).
92
99
#
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
98
108
# status is still pending
99
109
_log_destroy_pending = True
100
110
0 commit comments