asyncio.eager_task_factory
Prev: asyncio.DatagramTransport | Up: asyncio | Next: asyncio.ensure_future
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.eager_task_factory
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import eager_task_factory
Signature & Overview
asyncio.eager_task_factory(loop, coro, *, eager_start=True, **kwargs)
asyncio.eager_task_factory() function.
Usage
import asyncio
async def main():
loop = asyncio.get_running_loop()
loop.set_task_factory(asyncio.eager_task_factory)
t = asyncio.create_task(asyncio.sleep(0, result="fast"))
assert await t == "fast"
asyncio.run(main())
Gotchas
- Requires Python 3.12+: Can change task execution ordering if code relies on
create_task()deferring start until the next event loop tick.
REPL Inspect
from asyncio import eager_task_factory
help(eager_task_factory)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/DatagramTransport Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/ensure_future Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractEventLoop Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractServer Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/all_tasks Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/as_completed Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Barrier shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseEventLoop shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseProtocol shared tags: #asyncio, #stdlib