@@ -73,15 +73,23 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
73
73
"""A coroutine wrapped in a Future."""
74
74
75
75
# An important invariant maintained while a Task not done:
76
+ # _fut_waiter is either None or a Future. The task can be
77
+ # in any of 3 states:
76
78
#
77
- # - Either _fut_waiter is None, and _step() is scheduled;
78
- # - or _fut_waiter is some Future, and _step() is *not* scheduled.
79
+ # - 1 (_fut_waiter is not None and not _fut_waiter.done());
80
+ # __step() is *not* scheduled and the Task is waiting for _fut_waiter.
81
+ # - 2 (_fut_waiter is None or _fut_waiter.done()), and __step() is scheduled;
82
+ # the Task is waiting for __step() to be executed.
83
+ # - 3 _fut_waiter is None and __step() is *not* scheduled;
84
+ # the Task is currently executing (in __step()).
79
85
#
80
- # The only transition from the latter to the former is through
81
- # _wakeup(). When _fut_waiter is not None, one of its callbacks
82
- # must be _wakeup().
86
+ # The only transition from 1 to 2 is through __wakeup(). __wakeup()
87
+ # leaves _fut_waiter in place.
88
+ # In state 1, one of the callbacks of __fut_waiter must be __wakeup().
89
+ # It transitions from 2 to 3 when __step() is executed, and it clears
90
+ # _fut_waiter to None.
83
91
84
- # If False, don't log a message if the task is destroyed whereas its
92
+ # If False, don't log a message if the task is destroyed while its
85
93
# status is still pending
86
94
_log_destroy_pending = True
87
95
0 commit comments