Re:Reasons for Python async/await
by cbsmith on Wednesday May 20, 2015 @06:35PM
(#9579818)
The problem I have with async with is that you've already got issues with the syntax for "with" context managers and generators.
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.
[ Parent
| on HN ]
Re:Reasons for Python async/await
by laurencerowe on Wednesday May 20, 2015 @10:52PM
(#9580701)
Are you sure? I only see __exit__() being called after the loop:
Python 3.4.2 (default, Dec 23 2014, 17:01:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from contextlib import contextmanager
>>> @contextmanager
... def printme():
... print('enter')
... yield
... print('exit')
...
>>> def my_generator():
... with printme():
... for x in range(3):
... yield x
...
>>> for x in my_generator():
... print(x)
...
enter
0
1
2
exit