Skip to content

Commit

Permalink
Clarify that every thread has its own default context in contextvars
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal committed Nov 8, 2022
1 parent 5ff81da commit 949fd5f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Doc/library/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and work with *Context Variables*. The :func:`~contextvars.copy_context`
function and the :class:`~contextvars.Context` class should be used to
manage the current context in asynchronous frameworks.

.. note::
By default, every thread will have a different default
:class:`~contextvars.Context`. This means that a
:class:`~contextvars.ContextVar` can generally be used as a drop-in
replacement for a :func:`threading.local` variable.

Context managers that have state should use Context Variables
instead of :func:`threading.local()` to prevent their state from
bleeding to other code unexpectedly, when used in concurrent code.
Expand Down

0 comments on commit 949fd5f

Please sign in to comment.