ContextVar.reset()
ContextVar.reset() is a Python method in the ContextVars Module category. Resets the context variable to its previous value using the token from set(). The syntax is ContextVar.reset(token). Returns: None. A typical example: token = user_id.set(42)
# ...
user_id.reset(token) # Back to previous value. A close sibling is contextvars.ContextVar(), which creates a context variable that has separate values in different async contexts. A close sibling is ContextVar.get(), which returns the value of the context variable for the current context. A close sibling is ContextVar.set(), which sets the value of the context variable for the current context. A close sibling is contextvars.copy_context(), which returns a copy of the current context (all context variables and their values). More about this category: Context variables for async — ContextVar, copy_context, Context. Related ContextVars Module entries: contextvars.ContextVar(), ContextVar.get(), ContextVar.set(), contextvars.copy_context(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.