@@ -81,15 +81,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
81
81
"""A coroutine wrapped in a Future."""
82
82
83
83
# 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:
84
87
#
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()).
87
94
#
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
93
103
# status is still pending
94
104
_log_destroy_pending = True
95
105
0 commit comments