On this page
  1. asyncio.create_task
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

asyncio.create_task

Prev: asyncio.create_subprocess_shell | Up: asyncio | Next: asyncio.current_task
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.create_task
Tags: #public #python3 #stdlib #asyncio


Import

import asyncio
from asyncio import create_task

Signature & Overview

asyncio.create_task(coro, **kwargs)

Schedule the execution of a coroutine object in a spawn task.

Usage

import asyncio

async def double(x: int) -> int:
    await asyncio.sleep(0)
    return x * 2

async def main():
    task = asyncio.create_task(double(21), name="double-21")
    assert await task == 42

asyncio.run(main())

Gotchas

REPL Inspect

from asyncio import create_task
help(create_task)

Linked from

Related notes