def handle_ctrl_c():
 oldhook = sys.excepthook
 def newhook(exctype, value, traceback):
  if (exctype == KeyboardInterrupt):
   log('\nInterrupted.\n')
  else:
   return oldhook(exctype, value, traceback)
 sys.excepthook = newhook

def handle_ctrl_c ( ) : oldhook = sys . excepthook def newhook ( exctype , value , traceback ) : if ( exctype == KeyboardInterrupt ) : log ( '\nInterrupted.\n' ) else : return oldhook ( exctype , value , traceback ) sys . excepthook = newhook
replace the default exception handler for keyboardinterrupt .