On this page
asyncio.ensure_future
Prev: asyncio.eager_task_factory | Up: asyncio | Next: asyncio.Event
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.ensure_future
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import ensure_future
Signature & Overview
asyncio.ensure_future(coro_or_future, *, loop=None)
Wrap a coroutine or an awaitable in a future.
Usage
import asyncio
async def main():
fut = asyncio.ensure_future(asyncio.sleep(0, result=7))
assert await fut == 7
asyncio.run(main())
Gotchas
- Prefer
asyncio.create_task()for coroutines: Reach forensure_future()only in library code that must accept either a coroutine or an already-createdFuture.
REPL Inspect
from asyncio import ensure_future
help(ensure_future)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/eager_task_factory Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Event 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