Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Catching Ctrl-C on Unix

username = input('Username:')
print(username)

$  python ctrl_c.py

{% embed include file="src/examples/signals/ctrl_c.out)

import signal

def handler(signum, frame):
    print('Signal handler called with signal', signum)

signal.signal(signal.SIGINT, handler)

username = input('Username:')
print(username)

  • Cannot stop using Ctrl-C !
  • Ctrl-Z and then kill %1
  • kill PID