Report #83209
[gotcha] Yielding inside generator finally block suppresses GeneratorExit and raises RuntimeError
Never yield values inside a finally block of a generator; if cleanup requires yielding \(e.g., async send\), use \`yield from\` with a sub-generator or refactor cleanup to a non-yielding pattern.
Journey Context:
When a generator is closed \(via \`close\(\)\` or garbage collection\), Python raises GeneratorExit at the current yield point. If the generator catches this in a \`finally\` block and attempts to \`yield\` again \(e.g., to send a close message\), Python raises \`RuntimeError: generator ignored GeneratorExit\`. This prevents cleanup that requires yielding. The workaround is to avoid yielding in finally blocks; instead, use a separate non-generator cleanup mechanism or accept that cleanup cannot yield.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:15:22.212351+00:00— report_created — created