Skip to content

exec: send kernel interrupt on Ctrl+C#12

Merged
anish749 merged 2 commits into
mainfrom
ctrl-c-interrupt
Mar 30, 2026
Merged

exec: send kernel interrupt on Ctrl+C#12
anish749 merged 2 commits into
mainfrom
ctrl-c-interrupt

Conversation

@anish749

Copy link
Copy Markdown
Owner

Problem

When the CLI client is interrupted (Ctrl+C) during nbexec exec, the CLI process dies but the daemon continues executing the cell on the remote kernel. The result is lost (socket closed) but the kernel keeps running indefinitely.

Solution

Catch KeyboardInterrupt in _exec_one and send an INTERRUPT request to the daemon before propagating. This makes Ctrl+C behave identically to nbexec interrupt --session <id>.

Key details:

  • _send_interrupt() temporarily ignores SIGINT while sending the interrupt request (prevents a second Ctrl+C from breaking cleanup)
  • Best-effort: if the interrupt request fails, the CLI still exits cleanly
  • Notebook runs write partial results to the output notebook before exiting
  • Exit code 130 (standard SIGINT convention: 128 + 2)

Testing

4 new tests covering: single-cell interrupt, mid-notebook interrupt, partial output on interrupt, and interrupt-send failure resilience.

When the CLI receives KeyboardInterrupt during execution, send an
INTERRUPT request to the daemon before exiting. This ensures the
remote kernel stops executing rather than continuing silently after
the client disconnects.

Partial results are still written to the output notebook. Exit code
is 130 (standard SIGINT convention).
Race EXEC execution against reader.read(1) to detect client
disconnect (EOF). When the CLI process is killed (SIGKILL from
Claude Code cancel, or any other sudden death), the daemon now
detects the closed socket and interrupts the remote kernel
automatically.

Also adds pytest-asyncio as a test dependency and configures
asyncio_mode=auto in pyproject.toml.
@anish749 anish749 merged commit 659cdd2 into main Mar 30, 2026
1 check passed
@anish749 anish749 deleted the ctrl-c-interrupt branch March 30, 2026 09:20
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.

1 participant