Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../asyncio
File: tasks.py
"""Support for tasks, coroutines and the scheduler."""
[0] Fix | Delete
[1] Fix | Delete
__all__ = ['Task',
[2] Fix | Delete
'FIRST_COMPLETED', 'FIRST_EXCEPTION', 'ALL_COMPLETED',
[3] Fix | Delete
'wait', 'wait_for', 'as_completed', 'sleep', 'async',
[4] Fix | Delete
'gather', 'shield', 'ensure_future', 'run_coroutine_threadsafe',
[5] Fix | Delete
]
[6] Fix | Delete
[7] Fix | Delete
import concurrent.futures
[8] Fix | Delete
import functools
[9] Fix | Delete
import inspect
[10] Fix | Delete
import warnings
[11] Fix | Delete
import weakref
[12] Fix | Delete
[13] Fix | Delete
from . import base_tasks
[14] Fix | Delete
from . import compat
[15] Fix | Delete
from . import coroutines
[16] Fix | Delete
from . import events
[17] Fix | Delete
from . import futures
[18] Fix | Delete
from .coroutines import coroutine
[19] Fix | Delete
[20] Fix | Delete
[21] Fix | Delete
class Task(futures.Future):
[22] Fix | Delete
"""A coroutine wrapped in a Future."""
[23] Fix | Delete
[24] Fix | Delete
# An important invariant maintained while a Task not done:
[25] Fix | Delete
#
[26] Fix | Delete
# - Either _fut_waiter is None, and _step() is scheduled;
[27] Fix | Delete
# - or _fut_waiter is some Future, and _step() is *not* scheduled.
[28] Fix | Delete
#
[29] Fix | Delete
# The only transition from the latter to the former is through
[30] Fix | Delete
# _wakeup(). When _fut_waiter is not None, one of its callbacks
[31] Fix | Delete
# must be _wakeup().
[32] Fix | Delete
[33] Fix | Delete
# Weak set containing all tasks alive.
[34] Fix | Delete
_all_tasks = weakref.WeakSet()
[35] Fix | Delete
[36] Fix | Delete
# Dictionary containing tasks that are currently active in
[37] Fix | Delete
# all running event loops. {EventLoop: Task}
[38] Fix | Delete
_current_tasks = {}
[39] Fix | Delete
[40] Fix | Delete
# If False, don't log a message if the task is destroyed whereas its
[41] Fix | Delete
# status is still pending
[42] Fix | Delete
_log_destroy_pending = True
[43] Fix | Delete
[44] Fix | Delete
@classmethod
[45] Fix | Delete
def current_task(cls, loop=None):
[46] Fix | Delete
"""Return the currently running task in an event loop or None.
[47] Fix | Delete
[48] Fix | Delete
By default the current task for the current event loop is returned.
[49] Fix | Delete
[50] Fix | Delete
None is returned when called not in the context of a Task.
[51] Fix | Delete
"""
[52] Fix | Delete
if loop is None:
[53] Fix | Delete
loop = events.get_event_loop()
[54] Fix | Delete
return cls._current_tasks.get(loop)
[55] Fix | Delete
[56] Fix | Delete
@classmethod
[57] Fix | Delete
def all_tasks(cls, loop=None):
[58] Fix | Delete
"""Return a set of all tasks for an event loop.
[59] Fix | Delete
[60] Fix | Delete
By default all tasks for the current event loop are returned.
[61] Fix | Delete
"""
[62] Fix | Delete
if loop is None:
[63] Fix | Delete
loop = events.get_event_loop()
[64] Fix | Delete
return {t for t in cls._all_tasks if t._loop is loop}
[65] Fix | Delete
[66] Fix | Delete
def __init__(self, coro, *, loop=None):
[67] Fix | Delete
assert coroutines.iscoroutine(coro), repr(coro)
[68] Fix | Delete
super().__init__(loop=loop)
[69] Fix | Delete
if self._source_traceback:
[70] Fix | Delete
del self._source_traceback[-1]
[71] Fix | Delete
self._coro = coro
[72] Fix | Delete
self._fut_waiter = None
[73] Fix | Delete
self._must_cancel = False
[74] Fix | Delete
self._loop.call_soon(self._step)
[75] Fix | Delete
self.__class__._all_tasks.add(self)
[76] Fix | Delete
[77] Fix | Delete
# On Python 3.3 or older, objects with a destructor that are part of a
[78] Fix | Delete
# reference cycle are never destroyed. That's not the case any more on
[79] Fix | Delete
# Python 3.4 thanks to the PEP 442.
[80] Fix | Delete
if compat.PY34:
[81] Fix | Delete
def __del__(self):
[82] Fix | Delete
if self._state == futures._PENDING and self._log_destroy_pending:
[83] Fix | Delete
context = {
[84] Fix | Delete
'task': self,
[85] Fix | Delete
'message': 'Task was destroyed but it is pending!',
[86] Fix | Delete
}
[87] Fix | Delete
if self._source_traceback:
[88] Fix | Delete
context['source_traceback'] = self._source_traceback
[89] Fix | Delete
self._loop.call_exception_handler(context)
[90] Fix | Delete
futures.Future.__del__(self)
[91] Fix | Delete
[92] Fix | Delete
def _repr_info(self):
[93] Fix | Delete
return base_tasks._task_repr_info(self)
[94] Fix | Delete
[95] Fix | Delete
def get_stack(self, *, limit=None):
[96] Fix | Delete
"""Return the list of stack frames for this task's coroutine.
[97] Fix | Delete
[98] Fix | Delete
If the coroutine is not done, this returns the stack where it is
[99] Fix | Delete
suspended. If the coroutine has completed successfully or was
[100] Fix | Delete
cancelled, this returns an empty list. If the coroutine was
[101] Fix | Delete
terminated by an exception, this returns the list of traceback
[102] Fix | Delete
frames.
[103] Fix | Delete
[104] Fix | Delete
The frames are always ordered from oldest to newest.
[105] Fix | Delete
[106] Fix | Delete
The optional limit gives the maximum number of frames to
[107] Fix | Delete
return; by default all available frames are returned. Its
[108] Fix | Delete
meaning differs depending on whether a stack or a traceback is
[109] Fix | Delete
returned: the newest frames of a stack are returned, but the
[110] Fix | Delete
oldest frames of a traceback are returned. (This matches the
[111] Fix | Delete
behavior of the traceback module.)
[112] Fix | Delete
[113] Fix | Delete
For reasons beyond our control, only one stack frame is
[114] Fix | Delete
returned for a suspended coroutine.
[115] Fix | Delete
"""
[116] Fix | Delete
return base_tasks._task_get_stack(self, limit)
[117] Fix | Delete
[118] Fix | Delete
def print_stack(self, *, limit=None, file=None):
[119] Fix | Delete
"""Print the stack or traceback for this task's coroutine.
[120] Fix | Delete
[121] Fix | Delete
This produces output similar to that of the traceback module,
[122] Fix | Delete
for the frames retrieved by get_stack(). The limit argument
[123] Fix | Delete
is passed to get_stack(). The file argument is an I/O stream
[124] Fix | Delete
to which the output is written; by default output is written
[125] Fix | Delete
to sys.stderr.
[126] Fix | Delete
"""
[127] Fix | Delete
return base_tasks._task_print_stack(self, limit, file)
[128] Fix | Delete
[129] Fix | Delete
def cancel(self):
[130] Fix | Delete
"""Request that this task cancel itself.
[131] Fix | Delete
[132] Fix | Delete
This arranges for a CancelledError to be thrown into the
[133] Fix | Delete
wrapped coroutine on the next cycle through the event loop.
[134] Fix | Delete
The coroutine then has a chance to clean up or even deny
[135] Fix | Delete
the request using try/except/finally.
[136] Fix | Delete
[137] Fix | Delete
Unlike Future.cancel, this does not guarantee that the
[138] Fix | Delete
task will be cancelled: the exception might be caught and
[139] Fix | Delete
acted upon, delaying cancellation of the task or preventing
[140] Fix | Delete
cancellation completely. The task may also return a value or
[141] Fix | Delete
raise a different exception.
[142] Fix | Delete
[143] Fix | Delete
Immediately after this method is called, Task.cancelled() will
[144] Fix | Delete
not return True (unless the task was already cancelled). A
[145] Fix | Delete
task will be marked as cancelled when the wrapped coroutine
[146] Fix | Delete
terminates with a CancelledError exception (even if cancel()
[147] Fix | Delete
was not called).
[148] Fix | Delete
"""
[149] Fix | Delete
self._log_traceback = False
[150] Fix | Delete
if self.done():
[151] Fix | Delete
return False
[152] Fix | Delete
if self._fut_waiter is not None:
[153] Fix | Delete
if self._fut_waiter.cancel():
[154] Fix | Delete
# Leave self._fut_waiter; it may be a Task that
[155] Fix | Delete
# catches and ignores the cancellation so we may have
[156] Fix | Delete
# to cancel it again later.
[157] Fix | Delete
return True
[158] Fix | Delete
# It must be the case that self._step is already scheduled.
[159] Fix | Delete
self._must_cancel = True
[160] Fix | Delete
return True
[161] Fix | Delete
[162] Fix | Delete
def _step(self, exc=None):
[163] Fix | Delete
assert not self.done(), \
[164] Fix | Delete
'_step(): already done: {!r}, {!r}'.format(self, exc)
[165] Fix | Delete
if self._must_cancel:
[166] Fix | Delete
if not isinstance(exc, futures.CancelledError):
[167] Fix | Delete
exc = futures.CancelledError()
[168] Fix | Delete
self._must_cancel = False
[169] Fix | Delete
coro = self._coro
[170] Fix | Delete
self._fut_waiter = None
[171] Fix | Delete
[172] Fix | Delete
self.__class__._current_tasks[self._loop] = self
[173] Fix | Delete
# Call either coro.throw(exc) or coro.send(None).
[174] Fix | Delete
try:
[175] Fix | Delete
if exc is None:
[176] Fix | Delete
# We use the `send` method directly, because coroutines
[177] Fix | Delete
# don't have `__iter__` and `__next__` methods.
[178] Fix | Delete
result = coro.send(None)
[179] Fix | Delete
else:
[180] Fix | Delete
result = coro.throw(exc)
[181] Fix | Delete
except StopIteration as exc:
[182] Fix | Delete
if self._must_cancel:
[183] Fix | Delete
# Task is cancelled right before coro stops.
[184] Fix | Delete
self._must_cancel = False
[185] Fix | Delete
self.set_exception(futures.CancelledError())
[186] Fix | Delete
else:
[187] Fix | Delete
self.set_result(exc.value)
[188] Fix | Delete
except futures.CancelledError:
[189] Fix | Delete
super().cancel() # I.e., Future.cancel(self).
[190] Fix | Delete
except Exception as exc:
[191] Fix | Delete
self.set_exception(exc)
[192] Fix | Delete
except BaseException as exc:
[193] Fix | Delete
self.set_exception(exc)
[194] Fix | Delete
raise
[195] Fix | Delete
else:
[196] Fix | Delete
blocking = getattr(result, '_asyncio_future_blocking', None)
[197] Fix | Delete
if blocking is not None:
[198] Fix | Delete
# Yielded Future must come from Future.__iter__().
[199] Fix | Delete
if result._loop is not self._loop:
[200] Fix | Delete
self._loop.call_soon(
[201] Fix | Delete
self._step,
[202] Fix | Delete
RuntimeError(
[203] Fix | Delete
'Task {!r} got Future {!r} attached to a '
[204] Fix | Delete
'different loop'.format(self, result)))
[205] Fix | Delete
elif blocking:
[206] Fix | Delete
if result is self:
[207] Fix | Delete
self._loop.call_soon(
[208] Fix | Delete
self._step,
[209] Fix | Delete
RuntimeError(
[210] Fix | Delete
'Task cannot await on itself: {!r}'.format(
[211] Fix | Delete
self)))
[212] Fix | Delete
else:
[213] Fix | Delete
result._asyncio_future_blocking = False
[214] Fix | Delete
result.add_done_callback(self._wakeup)
[215] Fix | Delete
self._fut_waiter = result
[216] Fix | Delete
if self._must_cancel:
[217] Fix | Delete
if self._fut_waiter.cancel():
[218] Fix | Delete
self._must_cancel = False
[219] Fix | Delete
else:
[220] Fix | Delete
self._loop.call_soon(
[221] Fix | Delete
self._step,
[222] Fix | Delete
RuntimeError(
[223] Fix | Delete
'yield was used instead of yield from '
[224] Fix | Delete
'in task {!r} with {!r}'.format(self, result)))
[225] Fix | Delete
elif result is None:
[226] Fix | Delete
# Bare yield relinquishes control for one event loop iteration.
[227] Fix | Delete
self._loop.call_soon(self._step)
[228] Fix | Delete
elif inspect.isgenerator(result):
[229] Fix | Delete
# Yielding a generator is just wrong.
[230] Fix | Delete
self._loop.call_soon(
[231] Fix | Delete
self._step,
[232] Fix | Delete
RuntimeError(
[233] Fix | Delete
'yield was used instead of yield from for '
[234] Fix | Delete
'generator in task {!r} with {!r}'.format(
[235] Fix | Delete
self, result)))
[236] Fix | Delete
else:
[237] Fix | Delete
# Yielding something else is an error.
[238] Fix | Delete
self._loop.call_soon(
[239] Fix | Delete
self._step,
[240] Fix | Delete
RuntimeError(
[241] Fix | Delete
'Task got bad yield: {!r}'.format(result)))
[242] Fix | Delete
finally:
[243] Fix | Delete
self.__class__._current_tasks.pop(self._loop)
[244] Fix | Delete
self = None # Needed to break cycles when an exception occurs.
[245] Fix | Delete
[246] Fix | Delete
def _wakeup(self, future):
[247] Fix | Delete
try:
[248] Fix | Delete
future.result()
[249] Fix | Delete
except Exception as exc:
[250] Fix | Delete
# This may also be a cancellation.
[251] Fix | Delete
self._step(exc)
[252] Fix | Delete
else:
[253] Fix | Delete
# Don't pass the value of `future.result()` explicitly,
[254] Fix | Delete
# as `Future.__iter__` and `Future.__await__` don't need it.
[255] Fix | Delete
# If we call `_step(value, None)` instead of `_step()`,
[256] Fix | Delete
# Python eval loop would use `.send(value)` method call,
[257] Fix | Delete
# instead of `__next__()`, which is slower for futures
[258] Fix | Delete
# that return non-generator iterators from their `__iter__`.
[259] Fix | Delete
self._step()
[260] Fix | Delete
self = None # Needed to break cycles when an exception occurs.
[261] Fix | Delete
[262] Fix | Delete
[263] Fix | Delete
_PyTask = Task
[264] Fix | Delete
[265] Fix | Delete
[266] Fix | Delete
try:
[267] Fix | Delete
import _asyncio
[268] Fix | Delete
except ImportError:
[269] Fix | Delete
pass
[270] Fix | Delete
else:
[271] Fix | Delete
# _CTask is needed for tests.
[272] Fix | Delete
Task = _CTask = _asyncio.Task
[273] Fix | Delete
[274] Fix | Delete
[275] Fix | Delete
# wait() and as_completed() similar to those in PEP 3148.
[276] Fix | Delete
[277] Fix | Delete
FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
[278] Fix | Delete
FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION
[279] Fix | Delete
ALL_COMPLETED = concurrent.futures.ALL_COMPLETED
[280] Fix | Delete
[281] Fix | Delete
[282] Fix | Delete
@coroutine
[283] Fix | Delete
def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
[284] Fix | Delete
"""Wait for the Futures and coroutines given by fs to complete.
[285] Fix | Delete
[286] Fix | Delete
The sequence futures must not be empty.
[287] Fix | Delete
[288] Fix | Delete
Coroutines will be wrapped in Tasks.
[289] Fix | Delete
[290] Fix | Delete
Returns two sets of Future: (done, pending).
[291] Fix | Delete
[292] Fix | Delete
Usage:
[293] Fix | Delete
[294] Fix | Delete
done, pending = yield from asyncio.wait(fs)
[295] Fix | Delete
[296] Fix | Delete
Note: This does not raise TimeoutError! Futures that aren't done
[297] Fix | Delete
when the timeout occurs are returned in the second set.
[298] Fix | Delete
"""
[299] Fix | Delete
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
[300] Fix | Delete
raise TypeError("expect a list of futures, not %s" % type(fs).__name__)
[301] Fix | Delete
if not fs:
[302] Fix | Delete
raise ValueError('Set of coroutines/Futures is empty.')
[303] Fix | Delete
if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED):
[304] Fix | Delete
raise ValueError('Invalid return_when value: {}'.format(return_when))
[305] Fix | Delete
[306] Fix | Delete
if loop is None:
[307] Fix | Delete
loop = events.get_event_loop()
[308] Fix | Delete
[309] Fix | Delete
fs = {ensure_future(f, loop=loop) for f in set(fs)}
[310] Fix | Delete
[311] Fix | Delete
return (yield from _wait(fs, timeout, return_when, loop))
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
def _release_waiter(waiter, *args):
[315] Fix | Delete
if not waiter.done():
[316] Fix | Delete
waiter.set_result(None)
[317] Fix | Delete
[318] Fix | Delete
[319] Fix | Delete
@coroutine
[320] Fix | Delete
def wait_for(fut, timeout, *, loop=None):
[321] Fix | Delete
"""Wait for the single Future or coroutine to complete, with timeout.
[322] Fix | Delete
[323] Fix | Delete
Coroutine will be wrapped in Task.
[324] Fix | Delete
[325] Fix | Delete
Returns result of the Future or coroutine. When a timeout occurs,
[326] Fix | Delete
it cancels the task and raises TimeoutError. To avoid the task
[327] Fix | Delete
cancellation, wrap it in shield().
[328] Fix | Delete
[329] Fix | Delete
If the wait is cancelled, the task is also cancelled.
[330] Fix | Delete
[331] Fix | Delete
This function is a coroutine.
[332] Fix | Delete
"""
[333] Fix | Delete
if loop is None:
[334] Fix | Delete
loop = events.get_event_loop()
[335] Fix | Delete
[336] Fix | Delete
if timeout is None:
[337] Fix | Delete
return (yield from fut)
[338] Fix | Delete
[339] Fix | Delete
waiter = loop.create_future()
[340] Fix | Delete
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
[341] Fix | Delete
cb = functools.partial(_release_waiter, waiter)
[342] Fix | Delete
[343] Fix | Delete
fut = ensure_future(fut, loop=loop)
[344] Fix | Delete
fut.add_done_callback(cb)
[345] Fix | Delete
[346] Fix | Delete
try:
[347] Fix | Delete
# wait until the future completes or the timeout
[348] Fix | Delete
try:
[349] Fix | Delete
yield from waiter
[350] Fix | Delete
except futures.CancelledError:
[351] Fix | Delete
fut.remove_done_callback(cb)
[352] Fix | Delete
fut.cancel()
[353] Fix | Delete
raise
[354] Fix | Delete
[355] Fix | Delete
if fut.done():
[356] Fix | Delete
return fut.result()
[357] Fix | Delete
else:
[358] Fix | Delete
fut.remove_done_callback(cb)
[359] Fix | Delete
fut.cancel()
[360] Fix | Delete
raise futures.TimeoutError()
[361] Fix | Delete
finally:
[362] Fix | Delete
timeout_handle.cancel()
[363] Fix | Delete
[364] Fix | Delete
[365] Fix | Delete
@coroutine
[366] Fix | Delete
def _wait(fs, timeout, return_when, loop):
[367] Fix | Delete
"""Internal helper for wait() and wait_for().
[368] Fix | Delete
[369] Fix | Delete
The fs argument must be a collection of Futures.
[370] Fix | Delete
"""
[371] Fix | Delete
assert fs, 'Set of Futures is empty.'
[372] Fix | Delete
waiter = loop.create_future()
[373] Fix | Delete
timeout_handle = None
[374] Fix | Delete
if timeout is not None:
[375] Fix | Delete
timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
[376] Fix | Delete
counter = len(fs)
[377] Fix | Delete
[378] Fix | Delete
def _on_completion(f):
[379] Fix | Delete
nonlocal counter
[380] Fix | Delete
counter -= 1
[381] Fix | Delete
if (counter <= 0 or
[382] Fix | Delete
return_when == FIRST_COMPLETED or
[383] Fix | Delete
return_when == FIRST_EXCEPTION and (not f.cancelled() and
[384] Fix | Delete
f.exception() is not None)):
[385] Fix | Delete
if timeout_handle is not None:
[386] Fix | Delete
timeout_handle.cancel()
[387] Fix | Delete
if not waiter.done():
[388] Fix | Delete
waiter.set_result(None)
[389] Fix | Delete
[390] Fix | Delete
for f in fs:
[391] Fix | Delete
f.add_done_callback(_on_completion)
[392] Fix | Delete
[393] Fix | Delete
try:
[394] Fix | Delete
yield from waiter
[395] Fix | Delete
finally:
[396] Fix | Delete
if timeout_handle is not None:
[397] Fix | Delete
timeout_handle.cancel()
[398] Fix | Delete
[399] Fix | Delete
done, pending = set(), set()
[400] Fix | Delete
for f in fs:
[401] Fix | Delete
f.remove_done_callback(_on_completion)
[402] Fix | Delete
if f.done():
[403] Fix | Delete
done.add(f)
[404] Fix | Delete
else:
[405] Fix | Delete
pending.add(f)
[406] Fix | Delete
return done, pending
[407] Fix | Delete
[408] Fix | Delete
[409] Fix | Delete
# This is *not* a @coroutine! It is just an iterator (yielding Futures).
[410] Fix | Delete
def as_completed(fs, *, loop=None, timeout=None):
[411] Fix | Delete
"""Return an iterator whose values are coroutines.
[412] Fix | Delete
[413] Fix | Delete
When waiting for the yielded coroutines you'll get the results (or
[414] Fix | Delete
exceptions!) of the original Futures (or coroutines), in the order
[415] Fix | Delete
in which and as soon as they complete.
[416] Fix | Delete
[417] Fix | Delete
This differs from PEP 3148; the proper way to use this is:
[418] Fix | Delete
[419] Fix | Delete
for f in as_completed(fs):
[420] Fix | Delete
result = yield from f # The 'yield from' may raise.
[421] Fix | Delete
# Use result.
[422] Fix | Delete
[423] Fix | Delete
If a timeout is specified, the 'yield from' will raise
[424] Fix | Delete
TimeoutError when the timeout occurs before all Futures are done.
[425] Fix | Delete
[426] Fix | Delete
Note: The futures 'f' are not necessarily members of fs.
[427] Fix | Delete
"""
[428] Fix | Delete
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
[429] Fix | Delete
raise TypeError("expect a list of futures, not %s" % type(fs).__name__)
[430] Fix | Delete
loop = loop if loop is not None else events.get_event_loop()
[431] Fix | Delete
todo = {ensure_future(f, loop=loop) for f in set(fs)}
[432] Fix | Delete
from .queues import Queue # Import here to avoid circular import problem.
[433] Fix | Delete
done = Queue(loop=loop)
[434] Fix | Delete
timeout_handle = None
[435] Fix | Delete
[436] Fix | Delete
def _on_timeout():
[437] Fix | Delete
for f in todo:
[438] Fix | Delete
f.remove_done_callback(_on_completion)
[439] Fix | Delete
done.put_nowait(None) # Queue a dummy value for _wait_for_one().
[440] Fix | Delete
todo.clear() # Can't do todo.remove(f) in the loop.
[441] Fix | Delete
[442] Fix | Delete
def _on_completion(f):
[443] Fix | Delete
if not todo:
[444] Fix | Delete
return # _on_timeout() was here first.
[445] Fix | Delete
todo.remove(f)
[446] Fix | Delete
done.put_nowait(f)
[447] Fix | Delete
if not todo and timeout_handle is not None:
[448] Fix | Delete
timeout_handle.cancel()
[449] Fix | Delete
[450] Fix | Delete
@coroutine
[451] Fix | Delete
def _wait_for_one():
[452] Fix | Delete
f = yield from done.get()
[453] Fix | Delete
if f is None:
[454] Fix | Delete
# Dummy value from _on_timeout().
[455] Fix | Delete
raise futures.TimeoutError
[456] Fix | Delete
return f.result() # May raise f.exception().
[457] Fix | Delete
[458] Fix | Delete
for f in todo:
[459] Fix | Delete
f.add_done_callback(_on_completion)
[460] Fix | Delete
if todo and timeout is not None:
[461] Fix | Delete
timeout_handle = loop.call_later(timeout, _on_timeout)
[462] Fix | Delete
for _ in range(len(todo)):
[463] Fix | Delete
yield _wait_for_one()
[464] Fix | Delete
[465] Fix | Delete
[466] Fix | Delete
@coroutine
[467] Fix | Delete
def sleep(delay, result=None, *, loop=None):
[468] Fix | Delete
"""Coroutine that completes after a given time (in seconds)."""
[469] Fix | Delete
if delay == 0:
[470] Fix | Delete
yield
[471] Fix | Delete
return result
[472] Fix | Delete
[473] Fix | Delete
if loop is None:
[474] Fix | Delete
loop = events.get_event_loop()
[475] Fix | Delete
future = loop.create_future()
[476] Fix | Delete
h = future._loop.call_later(delay,
[477] Fix | Delete
futures._set_result_unless_cancelled,
[478] Fix | Delete
future, result)
[479] Fix | Delete
try:
[480] Fix | Delete
return (yield from future)
[481] Fix | Delete
finally:
[482] Fix | Delete
h.cancel()
[483] Fix | Delete
[484] Fix | Delete
[485] Fix | Delete
def async_(coro_or_future, *, loop=None):
[486] Fix | Delete
"""Wrap a coroutine in a future.
[487] Fix | Delete
[488] Fix | Delete
If the argument is a Future, it is returned directly.
[489] Fix | Delete
[490] Fix | Delete
This function is deprecated in 3.5. Use asyncio.ensure_future() instead.
[491] Fix | Delete
"""
[492] Fix | Delete
[493] Fix | Delete
warnings.warn("asyncio.async() function is deprecated, use ensure_future()",
[494] Fix | Delete
DeprecationWarning,
[495] Fix | Delete
stacklevel=2)
[496] Fix | Delete
[497] Fix | Delete
return ensure_future(coro_or_future, loop=loop)
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function