[Python-ideas] PEP draft: context variables

Yury Selivanov yselivanov.ml at gmail.com
Tue Sep 5 11:18:13 EDT 2017


We'll add a reference to the "Can Execution Context be implemented
without modifying CPython?" section [1].

However, after skimming through the readme file, I didn't see any
examples or limitations that are relevant to PEP 550.  If the PEP gets
accepted, Twisted can simply add direct support for it (similarly to
asyncio). That would mean that users won't need to maintain the
context manually (described in txlocal's "Maintaining Context"
section).

Yury

[1] https://www.python.org/dev/peps/pep-0550/#can-execution-context-be-implemented-without-modifying-cpython

On Tue, Sep 5, 2017 at 8:00 AM, Kevin Conway <kevinjacobconway at gmail.com> wrote:
> You should add https://bitbucket.org/hipchat/txlocal as a reference for the
> pep as it largely implements this idea for Twisted. It may provide for some
> practical discussions of use cases and limitations of this approach.
>
>
> On Tue, Sep 5, 2017, 09:55 Guido van Rossum <guido at python.org> wrote:
>>
>> On Tue, Sep 5, 2017 at 7:42 AM, Neil Girdhar <mistersheik at gmail.com>
>> wrote:
>>>
>>> I think you really should add a context manager to PEP 550 since it is
>>> better than calling "set", which leaks state.  Nathaniel is right that you
>>> need set to support legacy numpy methods like seterr.  Had there been a way
>>> of setting context variables using a context manager, then numpy would only
>>> have had to implement the "errstate" context manager on top of it.  There
>>> would have been no need for seterr, which leaks state between code blocks
>>> and is error-prone.
>>
>>
>> There is nothing in current Python to prevent numpy to use a context
>> manager for seterr; it's easy enough to write your own context manager that
>> saves and restores thread-local state (decimal shows how). In fact with PEP
>> 550 it's so easy that it's really not necessary for the PEP to define this
>> as a separate API -- whoever needs it can just write their own.
>>
>> --
>> --Guido van Rossum (python.org/~guido)
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


More information about the Python-ideas mailing list