@@ -73,15 +73,23 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
7373 """A coroutine wrapped in a Future."""
7474
7575 # 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:
7678 #
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()).
7985 #
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().
83-
84- # If False, don't log a message if the task is destroyed whereas its
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.
91+
92+ # If False, don't log a message if the task is destroyed while its
8593 # status is still pending
8694 _log_destroy_pending = True
8795
0 commit comments