Repository navigation
CLI: an abort while reading input does not end the session - #2122
Closed
tombouctou wants to merge 3 commits into
Closed
tombouctou wants to merge 3 commits into
tombouctou wants to merge 3 commits into
Conversation
The interrupt menu raises AbortInterrupt from the SIGINT handler. When the handler runs while the CLI reads input, no evaluation is there to catch it: it left interactive_eval_loop and ended the session with a traceback. Now the loop drops the input being typed and shows a new prompt. Reaching it takes a SIGINT that Python handles inside input(). With readline, Ctrl-C at the prompt does not get there: readline handles it. It does when the line was typed before readline set up the terminal, as a script driving the CLI in a pseudo-terminal does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… leaves installed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
LGTM. With respect to the "black" problems on the PRs, if you install Python's It will run black, isort, and mypy as the first part of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while testing Ctrl-C for #2121 by driving the CLI through a pseudo-terminal.
The interrupt menu's "abort" raises
AbortInterruptfrom the SIGINT handler. When the handler runs while the CLI is reading input, there's no evaluation to catch it, so it escapesinteractive_eval_loopand ends the session with a traceback (exit code 1):Now the loop drops the input being typed and shows a new prompt.
How hard is it to hit? Hard, in an ordinary terminal. With readline, Ctrl-C at the prompt never reaches Mathics' handler: readline deals with it. It does reach the handler when a line was typed before readline set up the terminal, which is what a script driving the CLI does. I reproduced it that way every time. A fast paste, or another front end, might hit it too. The fix is a single
exceptclause in the read-eval loop.Test:
test/test_repl_abort_at_prompt.pyrunsinteractive_eval_loopwith a shell whoseread_line()raisesAbortInterrupt(as the handler does insideinput()), then reads6*7. The session must go on and print 42. The test fails without the fix.🤖 Generated with Claude Code