refactor(hooks): fold the interrupt-path comments into one WHY line

The two inline comments on the BaseException branch restated what the code
does; keep only the reason the branch exists (own process group means the
terminal's SIGINT never reaches the hook).
This commit is contained in:
teknium1
2026-09-12 07:04:44 -07:00
committed by Teknium
parent f8fbf7c385
commit 761fa5d497
+2 -3
View File
@@ -318,12 +318,11 @@ def _spawn(spec: ShellHookSpec, stdin_json: str) -> Dict[str, Any]:
try:
stdout, stderr = proc.communicate(input=stdin_json, timeout=spec.timeout)
except BaseException as exc:
# BaseException, not Exception: Ctrl+C raises KeyboardInterrupt here, and the hook leads its own
# process group (above), so the terminal's SIGINT never reaches it — it would keep running.
# BaseException: the hook leads its own process group, so Ctrl+C's SIGINT never reaches it — only we can.
kill_process_tree(proc) # the whole tree — forked helpers holding the pipes would stall the drain
with suppress(Exception):
proc.communicate(timeout=1)
if not isinstance(exc, Exception): # KeyboardInterrupt / SystemExit: reap the hook, then propagate
if not isinstance(exc, Exception):
raise
if not isinstance(exc, subprocess.TimeoutExpired): # pragma: no cover — defensive
return failed(str(exc))