Skip to content

Instantly share code, notes, and snippets.

@msmhrt
Created August 21, 2014 15:48
Show Gist options
  • Save msmhrt/1518943127031f70b36a to your computer and use it in GitHub Desktop.
Save msmhrt/1518943127031f70b36a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from contextlib import contextmanager
@contextmanager
def ctxmgr():
print('before')
def inner_generator():
while True:
print((yield))
generator = inner_generator()
next(generator)
yield generator
print('after')
if __name__ == '__main__':
with ctxmgr() as c:
c.send('inner')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment