[Python-ideas] async/await in Python

Yury Selivanov yselivanov.ml at gmail.com
Sat Apr 18 00:40:01 CEST 2015


Andrew,


On 2015-04-17 6:26 PM, Andrew Barnert wrote:
> On Apr 17, 2015, at 15:18, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
>> Hi Chris,
[...]
>>
>>>
>>> Overall comment: The changes appear to be infecting a lot of code.
>>> Will this suddenly be something that everyone has to think about, or
>>> can it still be ignored in projects that don't use it?
>> If you're not writing some asynchronous code or using some
>> asynchronous library that takes advantage of coroutines, you
>> can completely ignore the new syntax and protocols.
> Is that true?
>
> If I'm writing a general-purpose library, and it might be useful in someone else's async code, and I write a context manager that does the usual "close/destroy resources on __exit__ thing", shouldn't I really think about whether it should also be an async context manager?
You can still use regular 'with' and 'for' statements in your
async code.

If someone by accident tries to use your regular context
manager with 'async with' she'll get an exception.
>
> That raises another question: is there a reasonable parallel to the contextlib.contextmanager decorator for building simple async context managers? (Or, for that matter, for building simple context-manager-and-also-async-context-managers?)
No, I don't think that we can have something similar
to 'contextmanager' decorator.

That would require some kind of a 'metayield' keyword ;)

Thanks!

Yury


More information about the Python-ideas mailing list