Can anyone explain how the interrupt_main() method works in Python?
I've got this piece of Python code :
import time, thread
# ... 10 seconds break...
raise KeyboardInterrupt does not interrupt a
time.sleep(). The former is handled entirely inside the python interpreter, the latter invokes an operating system function.
So, in your case, the keyboard interrupt was handled, but only when
time.sleep() completed its system call.
Try this instead:
def g(): thread.start_new_thread(f, ()) for _ in range(10): time.sleep(1)