from thread import * from threading import * from time import * def interrupt(): sleep(1) print 'Interrupting main thread now' interrupt_main() def listen(): t = Thread(target=interrupt) t.start() try: b = raw_input() except KeyboardInterrupt: print 'Exception caught'