contextvars — Context Variables — Python 3.14.7 documentation

docs.python.org

Tin mới

queue — A synchronized queue class

_thread — Low-level threading API

Python Module Index

3.14.7 Documentation

The Python Standard Library

Concurrent Execution

Context Variables¶

This module provides APIs to manage, store, and access context-local state. The ContextVar class is used to declare and work with Context Variables. The copy_context() function and the Context class should be used to man

context manager protocol

Token objects are returned by the ContextVar.set() method. They can be passed to the ContextVar.reset() method to revert the value of the variable to what it was before the corresponding set. A single token cannot reset

collections.abc.Mapping

Context() creates an empty context with no values in it. To get a copy of the current context use the copy_context() function.

asyncio: Asynchronous I/O.

Context variables are natively supported in asyncio and are ready to be used without any extra configuration. For example, here is a simple echo server, that uses a context variable to make the address of a remote client