On this page
  1. asyncio.CancelledError
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

asyncio.CancelledError

Prev: asyncio.BufferedProtocol | Up: asyncio | Next: asyncio.capture_call_graph
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org โ€” asyncio.CancelledError
Tags: #public #python3 #stdlib #asyncio


Import

import asyncio
from asyncio import CancelledError

Signature & Overview

asyncio.CancelledError(...)

The Future or Task was cancelled.

Methods & Attributes

Usage

import asyncio

async def main():
    task = asyncio.create_task(asyncio.sleep(10))
    task.cancel()
    try:
        await task
    except asyncio.CancelledError:
        assert task.cancelled()

asyncio.run(main())

Gotchas

REPL Inspect

from asyncio import CancelledError
help(CancelledError)

Linked from

Related notes