This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: In the generator's try/finally statement a runtime error occurs when the generator is not exhausted
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, py.user
Priority: normal Keywords:

Created on 2012-05-03 22:22 by py.user, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg159883 - (view) Author: py.user (py.user) * Date: 2012-05-03 22:22
" 6. Allow "yield" to be used in try/finally blocks, since garbage
       collection or an explicit close() call would now allow the
       finally clause to execute."

"New syntax: yield allowed inside try-finally

    The syntax for generator functions is extended to allow a
    yield-statement inside a try-finally statement."

>>> def f():
...   try:
...     yield 1
...     yield 2
...     yield 3
...   finally:
...     yield 4
>>> g = f()
>>> next(g)
>>> next(g)
>>> g = f()
Exception RuntimeError: 'generator ignored GeneratorExit' in <generator object f at 0xb74d2504> ignored
msg159884 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-05-03 22:33
It means in the body of the try statement.
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58923
2012-05-03 22:33:17benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg159884

resolution: not a bug
2012-05-03 22:22:22py.usercreate