On this page
asyncio.create_eager_task_factory
Prev: asyncio.Condition | Up: asyncio | Next: asyncio.create_subprocess_exec
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.create_eager_task_factory
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import create_eager_task_factory
Signature & Overview
asyncio.create_eager_task_factory(custom_task_constructor)
Create a function suitable for use as a task factory on an event-loop.
Usage
import asyncio
async def main():
loop = asyncio.get_running_loop()
factory = asyncio.create_eager_task_factory(asyncio.Task)
loop.set_task_factory(factory)
assert await asyncio.create_task(asyncio.sleep(0, result=42)) == 42
asyncio.run(main())
Gotchas
- Requires Python 3.12+: Runs a new coroutine synchronously up to its first
awaitpoint—great for caching/fast-path coroutines that rarely suspend.
REPL Inspect
from asyncio import create_eager_task_factory
help(create_eager_task_factory)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/Condition Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/create_subprocess_exec 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