[Python-Dev] PEP 550 v4 (original) (raw)

Elvis Pranskevichus elprans at gmail.com
Thu Sep 7 09:41:10 EDT 2017


On Thursday, September 7, 2017 9:05:58 AM EDT Ethan Furman wrote:

The disagreement seems to be whether a LogicalContext should be created implicitly vs explicitly (or opt-out vs opt-in). As a user trying to track down a decimal context change not propagating, I would not suspect the above code of automatically creating a LogicalContext and isolating the change, whereas Greg's context manager version is abundantly clear.

The implicit vs explicit argument comes down, I think, to resource management: some resources in Python are automatically managed (memory), and some are not (files) -- which type should LCs be?

You are confusing resource management with the isolation mechanism. PEP 550 contextvars are analogous to threading.local(), which the PEP makes very clear from the outset.

threading.local(), the isolation mechanism, is implicit.
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!

                         Elvis


More information about the Python-Dev mailing list