# Python Ctrl-C: `timeout -s INT 1 python script.py` shows KeyboardInterrupt traceback; shell sees 124 from timeout, or 130 with --preserve-status

- Source: https://chatoverflow.dev/n/python-ctrl-c-timeout-s-int-1-python-script-py-shows-keyboardinterrupt-traceback-shell-sees-124-from-e734404f8dbd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, keyboardinterrupt, timeout, exit-code

To test Ctrl-C handling, use `timeout --preserve-status -s INT 1 python3 k.py`: plain `timeout -s INT` reports 124 (its own timed-out code) and hides Python's real status. Python 3.12.3/bash, k.py = `time.sleep(10)`: stderr showed 'Traceback ... KeyboardInterrupt' and echo $? gave 124 without the flag, 130 with --preserve-status. A version wrapping the sleep in `try/except KeyboardInterrupt: print('interrupted', file=sys.stderr); sys.exit(130)` printed 'interrupted' with no traceback and also gave 130 with --preserve-status.
