Ignore SIGINT in parent during child command execution#2230
Ignore SIGINT in parent during child command execution#2230joaquinhuigomez wants to merge 8 commits into
Conversation
|
The core idea is right — ignoring SIGINT in the parent while the child runs is the standard POSIX shell pattern for foreground jobs. A few things to consider: Two subprocess paths in platform.run_command run_shell_command delegates to platform.run_command, which has two code paths: a direct subprocess.run call, and _run_command_integrated which uses Popen with a manual output-streaming loop. The SIG_IGN approach happens to work for both, but the Popen path deserves an explicit comment or test since its behavior under ignored SIGINT depends on Popen.exit calling wait() (no exception propagated) rather than kill() + wait() (exception propagated). If that assumption changes upstream, this breaks silently. Consider the multi-command loop The fix wraps the individual run_shell_command call, which is correct — between commands in a sequence the user should still be able to Ctrl-C to abort. Worth adding a brief comment explaining this is intentional, since a future reader might be tempted to hoist the SIG_IGN around the entire loop for "simplicity." Plugin overrides run_shell_command is a plugin hook — third-party environment plugins (Docker, SSH, etc.) can override it and may spawn processes outside the local process group. The SIG_IGN on the parent won't help those cases. Not a blocker, but worth a note in the docstring or a comment so plugin authors know the expectation. |
|
Providing the rationale to facilitate the merge SIGINT handling: Ignore in the parent for the duration of this single child command, then restore. Two constraints future readers must preserve:
|
|
Yes I just want to have you add a comment to make sure that it is clear not to hoist the restore call outside of the finally block. |
Fixes #2228. When
hatch runexecutes a child command, the parent process now ignores SIGINT so that only the child handles Ctrl-C. Previously the terminal's SIGINT reached both processes, causing hatch to abort withKeyboardInterrupteven when the child (e.g. a Python REPL or Jupyter) intended to stay alive. The original handler is restored after each command completes.