[Python-Dev] PEP 550 v4
elprans at gmail.com
Thu Sep 7 10:17:15 EDT 2017
On Thursday, September 7, 2017 10:06:14 AM EDT Ethan Furman wrote:
> I might be, and I wouldn't be surprised. :) On the other hand, one
> can look at isolation as being a resource.
> > threading.local(), the isolation mechanism, is *implicit*.
> I don't think so. You don't get threading.local() unless you call it
> -- that makes it explicit.
> > decimal.localcontext() is an *explicit* resource manager that
> > relies on threading.local() magic. PEP 550 simply provides a
> > threading.local() alternative that works in tasks and generators.
> > That's it!
> The concern is *how* PEP 550 provides it:
> - explicitly, like threading.local(): has to be set up manually,
> preferably with a context manager
> - implicitly: it just happens under certain conditions
You literally replace threading.local() with contextvars.ContextVar():
_decimal_context = threading.local()
_decimal_context.context = ctx
_decimal_context = contextvars.ContextVar('decimal.Context')
More information about the Python-Dev