2019-04-12
Here in the post, I will share some examples about the contextvars (new in Python 3.7) and thread local.
Default Value In the module level, use ContextVar.set or directly setattr for a thread local variable, won’t successfully set a default value, the value set won’t take effect in another thread.
To ensure a default value, for contextvars
import contextvars context_var = contextvars.ContextVar("context_var", default=0) for thread local, a sub class of thread.
Continue reading