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

Guido van Rossum guido at python.org
Thu Oct 17 21:01:30 CEST 2013


On Thu, Oct 17, 2013 at 11:55 AM, Oscar Benjamin <oscar.j.benjamin at gmail.com
> 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).
> >
> > And the latter worries me (much more than the very localized behavior of
> > suppress) because I don't see any way to implement them safely and
> > correctly when mixing it with coroutines in today's Python (some of them
> > aren't even thread-safe), all of that while I expect coroutines will see
> > significantly more use in the very near future with yield from and
> > tulip's promotion of coroutine-style async.
>
> I maybe misunderstanding how the  coroutine-style async works but I
> would have thought that it would be as simple as: don't use
> global-state-restoring-context-managers around statements that yield
> control (it would be simpler if there was a good term for describing
> that kind of CM). That's simpler to implement and computationally
> cheaper than e.g. the thread-local state used by the decimal module.
>

Context managers that actually save and restore *global* state are already
not thread-safe, so concluding they are also not coroutine-safe (or
task-safe?) seems a small step.

I'd be more worried about context manager that use thread-local state --
there is no similar concept in Tulip.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131017/676ef3ad/attachment-0001.html>


More information about the Python-Dev mailing list