title: Catching Keyboard Interrupt with Raw Input
body: <p>I have a bit of python code to to try and make raw_input catch keyboard interrupts. If I run the code in this function it works perfectly fine. But if I run it in my program, the print statement is never made, indicating that the keyboard interrupt is not caught.  The program attempts to exit and fails until it escalates to SIGKILL, which of course works fine. My guess is somewhere else the keyboard interrupt is being caught, preventing the exception from running at all. My question is, where would such an interrupt likely occur, and how can I prevent it from blocking this one. My plan has been to add a slight delay between the program catching a keyboard interrupt and killing itself to give excepting here a moment to catch.</p>
  
  <p>Any ideas appreciated</p>
  
  <p>Thanks!</p>
  
  <pre><code>import sys
  def interruptable_input(text=''):
    '''Takes raw input, but accepts keyboard interrupt'''
    try:
      return raw_input(text)
    except KeyboardInterrupt:
      print "Interrupted by user"
      sys.exit()
  </code></pre>