From 9305fa4cac4de8ed91a5616c39a7c9a09f300274 Mon Sep 17 00:00:00 2001 From: Simon Brakhane Date: Mon, 12 Oct 2026 10:44:47 +0200 Subject: [PATCH] test: make the hard-kill scenario immune to SIGINT timing Test [6] simulated an uninterruptible cell with try/except KeyboardInterrupt around time.sleep. A SIGINT landing on the loop condition escaped the try, the cell ended on its own and the hard kill never happened, so result.killed was undefined and the kernel kept its pid (macOS, Python 3.14, CI run 38224762826). The cell now installs a no-op SIGINT handler, which swallows every interrupt wherever it lands. --- test-interrupt.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test-interrupt.ts b/test-interrupt.ts index ffafb4b..ee8f98c 100644 --- a/test-interrupt.ts +++ b/test-interrupt.ts @@ -207,7 +207,7 @@ async function main(): Promise { // // Regression test for the only failure mode that ever showed up in real // sessions: a cell wedged in something SIGINT can't reach (here, a - // Python-level handler that swallows every KeyboardInterrupt, standing + // Python-level SIGINT handler that swallows every interrupt, standing // in for a C extension). It used to reject the whole call with the bare // string "python kernel killed", discarding everything the cell had // printed. It must now resolve with that output plus killed=true. @@ -220,14 +220,17 @@ async function main(): Promise { [ { code: [ - "import time, sys", + "import signal, time", + // A no-op handler swallows every SIGINT wherever it lands. A + // try/except around the sleep did not: a SIGINT arriving on + // the loop condition escaped as KeyboardInterrupt, the cell + // ended on its own, and the hard kill never happened (seen on + // macOS + Python 3.14 in CI). + "signal.signal(signal.SIGINT, lambda *_: None) # like a C ext that never checks signals", "print('findings: 3 hosts reachable', flush=True)", "deadline = time.time() + 30", "while time.time() < deadline:", - " try:", - " time.sleep(0.05)", - " except KeyboardInterrupt:", - " pass # swallow it, like a C ext that never checks signals", + " time.sleep(0.05)", ].join("\n"), }, ],