Skip to content

Comment on Reasons for Python async/awaitparent

Comments

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
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.