Skip to content

Instantly share code, notes, and snippets.

@antocuni
Created May 8, 2020 09:22
Show Gist options
  • Save antocuni/38007a738536d1061337b1c739b79c30 to your computer and use it in GitHub Desktop.
Save antocuni/38007a738536d1061337b1c739b79c30 to your computer and use it in GitHub Desktop.
>>> def foo():
... try:
... print('start')
... yield 1
... yield 2
... print('bye')
... except GeneratorExit:
... print('forced exit')
...
>>> f = foo()
>>> next(f)
start
1
>>> next(f)
2
>>> next(f)
bye
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
>>>
>>> f = foo()
>>> next(f)
start
1
>>> next(f)
2
>>> del f
forced exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment