[Python-Dev] On suppress()'s trail blazing (was Re: cpython: Rename contextlib.ignored() to contextlib.ignore())

Stefan Krah stefan at bytereef.org
Thu Oct 17 22:05:24 CEST 2013


Xavier Morel <python-dev at masklinn.net> wrote:
> On 2013-10-17, at 20:55 , Oscar Benjamin wrote:
> > On 17 October 2013 19:40, Xavier Morel <python-dev at masklinn.net> wrote:
> >> I think there's already a significant split between context managers
> >> which handle the lifecycle of a local resource (file, transaction) and
> >> those which purport to locally alter global-ish state (cwd,
> >> decimal.localcontext, logging.captureWarnings, redirect_stdout).

Well, naming is difficult.  In the case of decimal it's a temporary global
but also thread-local context.


> You have to know which contextmanagers to what and how, and avoid them
> in these specific situations. I'm really bothered by these being unsafe
> by default. Technically they're already broken but the chance of them
> being used in such a context are low, whereas it wouldn't be unexpected
> for a user to e.g. create a local decimal context in a coroutine and
> *not* expect that local context to affect other coroutines running
> concurrently.

I don't think localcontext() is broken. The fine manual is quite clear
that "current contexts" are per thread. The localcontext() docs explicitly
say that the "current context" is swapped.


Of course there are multiple ways to use individual contexts for each
coroutine. Use the context methods or pass the context to the Decimal
methods.



Stefan Krah




More information about the Python-Dev mailing list