Skip to content

Commit 949fd5f

Browse files
committed
Clarify that every thread has its own default context in contextvars
1 parent 5ff81da commit 949fd5f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/library/contextvars.rst

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ and work with *Context Variables*. The :func:`~contextvars.copy_context`
1414
function and the :class:`~contextvars.Context` class should be used to
1515
manage the current context in asynchronous frameworks.
1616

17+
.. note::
18+
By default, every thread will have a different default
19+
:class:`~contextvars.Context`. This means that a
20+
:class:`~contextvars.ContextVar` can generally be used as a drop-in
21+
replacement for a :func:`threading.local` variable.
22+
1723
Context managers that have state should use Context Variables
1824
instead of :func:`threading.local()` to prevent their state from
1925
bleeding to other code unexpectedly, when used in concurrent code.

0 commit comments

Comments
 (0)