Coggle requires JavaScript to display documents.
asyncio.run(coro())
coro
asyncio.create_task(coro(), name=...)
Task
await
await coro()
async coro(): ...
coro()
asyncio.create_task(coro, *, name)
.cancel()
CancelledError
.result()
Exception
.exception()
.get_coro()
async def coro(): ... tasks = [asyncio.create_task(coro, name), ...] for task in tasks: result = await task # do smth with result
PYTHONASYNCIODEBUG=1
$ python -X dev ...
asyncio.run(debug=True)
logging.getLogger("asyncio").setLevel(logging.WARNING)
ResourceWarning
$ python -W default ...
PYTHONWARNINGS=default
warnings.simplefilter("default")
.call_soon_threadsafe()
eventloop.call_soon_threadsafe(callback, *args)
def callback(): ...
.run_coroutine_threadsafe()
async def coro(): ...
future = asyncio.run_coroutine_threadsafe(coro(), eventloop) # blocks until future is resolved or timeout occurs result = future.result(timeout)
.call_soon()
eventloop.call_soon(callback, *args)
args
.call_later()
loop.call_later(delay, callback, *args) -> asyncio.TimerHandle
callback
delay
asyncio.TimerHandle
.when()
.cancelled()
.call_at()
eventloop.call_at(timestamp, callback, *args) -> asyncio.TimerHandle
timestamp
eventloop.time()
.run_in_executor()
eventloop.run_in_executor(executor, func, *args)
func
executor
with concurrent.futures.ThreadPoolExecutor() as pool: result = await loop.run_in_executor(pool, blocking_io) print('custom thread pool', result)
.all_tasks()
.get_running_loop()
.current_task()
None
.set_exception_handler(handler)
handler