Core concept ''''''''''''
A context-local variable is represented by a single instance of
cvar. Any code that has access to the
object can ask for its value with respect to the current context. In the
high-level API, this value is given by the
cvar = contextvars.Var(default="the default value", description="example context variable") assert cvar.value == "the default value" # default still applies # In code examples, all ``assert`` statements should # succeed according to the proposed semantics.
Running code in a clean state '''''''''''''''''''''''''''''
Although it is possible to revert all applied context changes using the above primitives, a more convenient way to run a block of code in a clean context is provided::
with context_vars.clean_context(): # here, all context vars start off with their default values # here, the state is back to what it was before the with block.
why not to call the section 'Running code in the default state' and the
# here, all context vars start off with their default values
# here, the state is back to what it was before the with block.
default (the variable is constructed as
cvar = ontextvars.Var(default="the default value", ...) ?
Thanks in advance, --francis