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(): import threading _decimal_context = threading.local() def set_decimal_context(ctx): _decimal_context.context = ctx Becomes: import contextvars _decimal_context = contextvars.ContextVar('decimal.Context') def set_decimal_context(ctx): _decimal_context.set(ctx) Elvis _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com