From b6f314ec3cf80b244096249d7bb8adc48b9f6cbc Mon Sep 17 00:00:00 2001 From: Kotha Dhakshin <179742818+Dhakshin2007@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:07:44 +0530 Subject: [PATCH] fix: use correct POSIX signal exit convention for KeyboardInterrupt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using sys.exit(signal.SIGINT) exits with code 2, which shells and CI systems interpret as a regular error, not a signal-terminated process. The POSIX convention for a process terminated by signal N is to exit with code 128 + N. For SIGINT (N=2), this is exit code 130. The correct idiomatic approach is to reset SIGINT to its default handler and re-raise it — the OS then sets the exit status automatically, allowing shells and CI runners to correctly detect that the process was interrupted rather than failing with a generic error code. --- test.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index fe62bdb..8e33f86 100755 --- a/test.py +++ b/test.py @@ -150,5 +150,8 @@ def main() -> None: try: main() except KeyboardInterrupt: - # no stack trace on interrupt - sys.exit(signal.SIGINT) + # Re-raise SIGINT with the default handler so the OS sets exit code 130 + # (128 + SIGINT), correctly signalling an interrupted process to shells + # and CI systems, rather than exiting with a generic error code. + signal.signal(signal.SIGINT, signal.SIG_DFL) + os.kill(os.getpid(), signal.SIGINT)