@asyncio.coroutine defmy_coroutine(): print(f'I ain\'t got no money ({threading.currentThread()})') yieldfrom asyncio.sleep(1) print(f'Do not go gentle into that good night ({threading.currentThread()})')
I ain't got no money (<_MainThread(MainThread, started 14260)>) I ain't got no money (<_MainThread(MainThread, started 14260)>) Do not go gentle into that good night (<_MainThread(MainThread, started 14260)>) Do not go gentle into that good night (<_MainThread(MainThread, started 14260)>)
asyncdefmy_coroutine(): print(f'I ain\'t got no money ({threading.currentThread()})') await asyncio.sleep(1) print(f'Do not go gentle into that good night ({threading.currentThread()})')
Arrange for a callback to be called as soon as possible.This operates as a FIFO queue: callbacks are called in theorder in which they are registered. Each callback will becalled exactly once.Any positional arguments after the callback will be passed tothe callback when it is called.
asyncdefmy_coroutine(loop): print(f'I ain\'t got no money ({threading.currentThread()})') await asyncio.sleep(1) loop.call_soon(callback, 'first time') loop.call_soon(callback, 'second time') print(f'Do not go gentle into that good night ({threading.currentThread()})')
I ain't got no money (<_MainThread(MainThread, started 11056)>) I ain't got no money (<_MainThread(MainThread, started 11056)>) Do not go gentle into that good night (<_MainThread(MainThread, started 11056)>) Do not go gentle into that good night (<_MainThread(MainThread, started 11056)>) callback: first time (<_MainThread(MainThread, started 11056)>) callback: second time (<_MainThread(MainThread, started 11056)>) callback: first time (<_MainThread(MainThread, started 11056)>) callback: second time (<_MainThread(MainThread, started 11056)>)
Arrange for a callback to be called at a given time.Return a Handle: an opaque object with a cancel() method thatcan be used to cancel the call.The delay can be an int or float, expressed in seconds. It isalways relative to the current time.Each callback will be called exactly once. If two callbacksare scheduled for exactly the same time, it undefined whichwill be called first.Any positional arguments after the callback will be passed tothe callback when it is called.
asyncdefmy_coroutine(loop): print(f'I ain\'t got no money ({threading.currentThread()})') loop.call_later(0.4, callback, 'second time') loop.call_soon(callback, 'first time') await asyncio.sleep(0.5) print(f'Do not go gentle into that good night ({threading.currentThread()})')
I ain't got no money (<_MainThread(MainThread, started 17904)>) I ain't got no money (<_MainThread(MainThread, started 17904)>) callback: first time (<_MainThread(MainThread, started 17904)>) callback: first time (<_MainThread(MainThread, started 17904)>) callback: second time (<_MainThread(MainThread, started 17904)>) callback: second time (<_MainThread(MainThread, started 17904)>) Do not go gentle into that good night (<_MainThread(MainThread, started 17904)>) Do not go gentle into that good night (<_MainThread(MainThread, started 17904)>)
asyncdefmy_coroutine(loop): print(f'I ain\'t got no money ({threading.currentThread()})') loop.call_at(loop.time() + 0.2, callback, 'second time') loop.call_soon(callback, 'first time') await asyncio.sleep(0.5) print(f'Do not go gentle into that good night ({threading.currentThread()})')
I ain't got no money (<_MainThread(MainThread, started 18504)>) I ain't got no money (<_MainThread(MainThread, started 18504)>) callback: first time (<_MainThread(MainThread, started 18504)>) callback: first time (<_MainThread(MainThread, started 18504)>) callback: second time (<_MainThread(MainThread, started 18504)>) callback: second time (<_MainThread(MainThread, started 18504)>) Do not go gentle into that good night (<_MainThread(MainThread, started 18504)>) Do not go gentle into that good night (<_MainThread(MainThread, started 18504)>)