Lightning-AI / Lightning-AI/lightning-thunder

in generators (and async generators / coroutines, too), exception handling during yield should be done by the generator

Open
#815 3 comments 0 reactions 0 assignees View on GitHub
bug interpreter
Dominant language
Python
Stars
1.5k
Forks
121
PR merge metrics
No merged PRs in 30d

Description

Currently in generators, we catch exceptions during the yield and raise them. This is not correct, we should be setting the error and let the frame do the error handling. In other words, the current implementation ignores try blocks when the error happens during `yield`.

https://github.com/Lightning-AI/lightning-thunder/blob/d15b64c71aca487397c47452ac6872d853d9acda/thunder/core/interpreter.py#L5888-L5894

This is also the only occasion when Python 3.12 reaches the `CLEANUP_THROW` opcode.

cc @apaz-cli

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in thunder/core/interpreter.py at lines 5888-5894 and trace how generators handle exceptions during yield. Compare that path with the frame's error handling, including the CLEANUP_THROW opcode reached by Python 3.12. Done means try blocks handle exceptions raised during yield correctly for generators, async generators, and coroutines.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.