def interrupt_main():
 if _main:
  raise KeyboardInterrupt
 else:
  global _interrupt
  _interrupt = True

def interrupt_main ( ) : if _main : raise KeyboardInterrupt else : global _interrupt _interrupt = True
set _interrupt flag to true to have start_new_thread raise keyboardinterrupt upon exiting .