For context on this, check out PEP 492: <a href="https://www.python.org/dev/peps/pep-0492/" rel="nofollow">https://www.python.org/dev/peps/pep-0492/</a><p>It's a really exciting proposal. AFAIK, it'd make Python 3 the first mainstream imperative scripting language to have these async/await concepts built-in (there is a similar proposal for JavaScript/ES7 built on top of generators and promises[1]). While I've commented before about how asyncio is still a bit more nascent than I'd like, I'm really excited to see where the community takes it.<p>[1]: <a href="https://github.com/lukehoban/ecmascript-asyncawait" rel="nofollow">https://github.com/lukehoban/ecmascript-asyncawait</a>
Related: <a href="http://queue.acm.org/detail.cfm?ref=rss&id=2747873" rel="nofollow">http://queue.acm.org/detail.cfm?ref=rss&id=2747873</a><p>This is the ACM Queue paper about async/await in Dart (iirc according to Erik Meijer the cleanest implementation of the concept so far).
The problem I have with async with is that you've already got issues with the syntax for "with" context managers and generators.<p><pre><code> def my_generator():
with something() as bar:
for x in baz():
yield bar(x) # context manager will call bar.__exit__() before the second time through this loop.
</code></pre>
It'd make a LOT more sense to just make "with" understand when it is in a continuation and only invoke __exit__() when the continuation is being destroyed.
It seems to me like this is a feature that will only be used by 1% of Python programmers. I'm lacking a lot of context but personally I'd much prefer it if Guido spent his time fixing the Python 2/3 conundrum. And even though these proposed changes are Python 3 only, the fact that only so few people will use them doesn't do much in that regard.
The nice thing about Python generator functions was that they didn't need a lot of syntax - if a function contains the "yield" keyword, it's a generator, otherwise it's not.<p>Given how closely tied generators are with async/await, why do we need "async def"? Isn't the presence of "await" or "async for" or "async with" enough to mark a function as asynchronous?