This commit is contained in:
ton
2024-10-07 10:13:40 +07:00
parent aa1631742f
commit 3a7d696db6
9729 changed files with 1832837 additions and 161742 deletions

View File

@@ -86,15 +86,25 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
"""A coroutine wrapped in a Future."""
# An important invariant maintained while a Task not done:
# _fut_waiter is either None or a Future. The Future
# can be either done() or not done().
# The task can be in any of 3 states:
#
# - Either _fut_waiter is None, and _step() is scheduled;
# - or _fut_waiter is some Future, and _step() is *not* scheduled.
# - 1: _fut_waiter is not None and not _fut_waiter.done():
# __step() is *not* scheduled and the Task is waiting for _fut_waiter.
# - 2: (_fut_waiter is None or _fut_waiter.done()) and __step() is scheduled:
# the Task is waiting for __step() to be executed.
# - 3: _fut_waiter is None and __step() is *not* scheduled:
# the Task is currently executing (in __step()).
#
# The only transition from the latter to the former is through
# _wakeup(). When _fut_waiter is not None, one of its callbacks
# must be _wakeup().
# * In state 1, one of the callbacks of __fut_waiter must be __wakeup().
# * The transition from 1 to 2 happens when _fut_waiter becomes done(),
# as it schedules __wakeup() to be called (which calls __step() so
# we way that __step() is scheduled).
# * It transitions from 2 to 3 when __step() is executed, and it clears
# _fut_waiter to None.
# If False, don't log a message if the task is destroyed whereas its
# If False, don't log a message if the task is destroyed while its
# status is still pending
_log_destroy_pending = True
@@ -470,7 +480,7 @@ async def wait_for(fut, timeout):
If the wait is cancelled, the task is also cancelled.
If the task supresses the cancellation and returns a value instead,
If the task suppresses the cancellation and returns a value instead,
that value is returned.
This function is a coroutine.