Skip to content

Close cells the pseudo-sync runner cannot finish - #15459

Open
jenshnielsen wants to merge 2 commits into
ipython:mainfrom
jenshnielsen:fix_generator_exit
Open

jenshnielsen wants to merge 2 commits into
ipython:mainfrom
jenshnielsen:fix_generator_exit

Conversation

@jenshnielsen

Copy link
Copy Markdown
Contributor

I ran into a corner case where generator exists suddenly showed up for seemingly random cells.

Claude has generated the below suggestion for a fix and an example here that shows the issue.

I admit that I am not a deep expert on how the async executor code works in ipython but I have validated the fix and the explanation makes sense to me.

Clauds explanation below:

When a cell needs an event loop but runs through _pseudo_sync_runner (e.g. in a shell whose should_run_async returns False), the runner raised RuntimeError but left the cell's coroutine suspended. The garbage collector closed it at some arbitrary later point, and the bare excepts in run_code and run_ast_nodes reported the resulting GeneratorExit as an error of whichever cell was running then, even replacing that cell's traceback.

Close the coroutine before raising, and let GeneratorExit from an async cell unwind through run_code and run_ast_nodes instead of reporting it.

When a cell needs an event loop but runs through _pseudo_sync_runner
(e.g. in a shell whose should_run_async returns False), the runner
raised RuntimeError but left the cell's coroutine suspended. The
garbage collector closed it at some arbitrary later point, and the
bare excepts in run_code and run_ast_nodes reported the resulting
GeneratorExit as an error of whichever cell was running then, even
replacing that cell's traceback.

Close the coroutine before raising, and let GeneratorExit from an async
cell unwind through run_code and run_ast_nodes instead of reporting it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Carreau Carreau added this to the 9.19 milestone Nov 2, 2026
Undoing a monkeypatch of a method on the shell instance leaves the bound
method behind as an instance attribute. That shadowed the class-level
showtraceback that test_set_show_tracebacks_none sets later, which made
it fail whenever it ran after this test, as in the oldest-deps jobs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants