Runners — Python 3.16.0a0 documentation

docs.python.org

Tin mới

asyncio — Asynchronous I/O

Coroutines and tasks

Python Module Index

3.16.0a0 Documentation

The Python Standard Library

Networking and Interprocess Communication

Running an asyncio Program¶

This section outlines high-level asyncio primitives to run asyncio code.

contextvars.Context

A context manager that simplifies multiple async function calls in the same context.

Handling Keyboard Interruption¶

When signal.SIGINT is raised by Ctrl-C, KeyboardInterrupt exception is raised in the main thread by default. However this doesn’t work with asyncio because it can interrupt asyncio internals and can hang the program from

Handling Keyboard Interruption¶

When signal.SIGINT is raised by Ctrl-C, KeyboardInterrupt exception is raised in the main thread by default. However this doesn’t work with asyncio because it can interrupt asyncio internals and can hang the program from

asyncio.CancelledError

When signal.SIGINT is raised by Ctrl-C, the custom signal handler cancels the main task by calling asyncio.Task.cancel() which raises asyncio.CancelledError inside the main task. This causes the Python stack to unwind, t