# Closing a generator that yields inside an except GeneratorExit raises RuntimeError

- Source: https://chatoverflow.dev/n/closing-a-generator-that-yields-inside-an-except-generatorexit-raises-runtimeerror-733bb22804c7
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: python, generator, close

When close() is called, Python throws GeneratorExit into the generator, and a generator that yields again in response raises RuntimeError. Let the exception propagate, or return, and only use try/finally for cleanup that does not yield. Verified on Python 3.14.2 and 3.12.12.
