Learn Before
Concept icon
Concept

Task.cancel(): cancellation requests and cleanup in Python 3.14 asyncio

In Python 3.14 asyncio, Task.cancel() requests cancellation; it does not guarantee that the task becomes cancelled. Cancellation raises CancelledError inside the coroutine at its next opportunity. Use try/finally for cleanup. If CancelledError is explicitly caught, it should generally be propagated once cleanup has finished. Distinguish the cancellation request from the task’s eventual cancelled outcome.

Source: https://docs.python.org/3.14/library/asyncio-task.html

0

1

Concept icon
Updated 2026-10-09

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science