Skip to content

Leaving the inspect dialog resumes the interrupted evaluation - #2123

Closed
tombouctou wants to merge 1 commit into
masterfrom
inspect-dialog-resumes
Closed

tombouctou wants to merge 1 commit into
masterfrom
inspect-dialog-resumes

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

Found while testing Ctrl-C for #2121 by driving the CLI through a pseudo-terminal.

Before: Ctrl-C during Pause[8]; 7, then i, then 1+1, then Ctrl-D:

interrupt> i
inspecting
Interrupt::dgbgn: Entering Dialog; enter Ctrl-D to exit.
        1+1
Out[1]= 2
        ^D
General::timeout: Timeout reached.
Out[2]= $Aborted

The dialog evaluates its input with the interrupted Evaluation object. Evaluation.evaluate() resets that object's state and ends with stop(), so once the dialog closes, the resumed evaluation finds stopped = True at its next check_stopped().

Now: the dialog saves the interrupted evaluation's state (stopped, timeout, deadline, counters, pending messages, ...) and puts it back after each input, as it already did for recursion_depth:

        ^D
Out[2]= 7

Test: test/test_interrupt_inspect.py runs inspect_eval_loop with a shell that types 1+1 and then Ctrl-D. The interrupted evaluation must come back not stopped, with its recursion depth and pending messages. It fails without the fix. I also checked the whole sequence end to end in a pseudo-terminal.

Not changed here: line numbers around a dialog. The dialog's 1+1 is labelled Out[1]. The resumed result is printed as Out[2]= 7 but stored as Out[1], and Out[2] is left unset ({Out[1], Out[2], $Line} gives {7, %2, 3}). Which numbers should a dialog and the resumed evaluation get? I didn't want to guess at WMA's behavior.

🤖 Generated with Claude Code

Ctrl-C during an evaluation, "inspect", some input, then Ctrl-D: the
interrupted evaluation stopped with "Timeout reached" and $Aborted rather
than going on. The dialog evaluates its input with the same Evaluation
object, and Evaluation.evaluate() resets its state and ends with stop(),
so the resumed evaluation found stopped = True at its next check.

The dialog now saves the interrupted evaluation's state (stopped, timeout,
deadline, counters, the pending messages, ...) and puts it back after each
input, as it already did for recursion_depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread mathics/interrupt.py
from mathics.eval.stackframe import find_Mathics3_evaluation_method, get_eval_Expression


# The state of an evaluation that Evaluation.evaluate() resets and leaves

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be an Enumeration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sense I am getting is that AI is good with several things, but it can use or tolerate older forms of Python, and also does not pick up that well on the existing style and practice of existing code (unless explicitly directed to). I suspect this is also why we see so many isort/black failures initially as well.

@rocky rocky closed this Nov 10, 2026
@rocky
rocky deleted the inspect-dialog-resumes branch November 10, 2026 11:49
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.

3 participants