title: Python main thread interruption
body: <p>Can anyone explain how the interrupt_main() method works in Python?</p>
  
  <p>I've got this piece of Python code : </p>
  
  <pre><code>import time, thread
  
  def f():
      time.sleep(5)
      thread.interrupt_main()
  
  def g():
      thread.start_new_thread(f, ())
      time.sleep(10)
  print time.time()
  try:
      g()
  except KeyboardInterrupt:
      print time.time()
  </code></pre>
  
  <p>And when I try to run it, it gives me the following output : </p>
  
  <pre><code>1380542215.5
  # ... 10 seconds break...
  1380542225.51
  </code></pre>
  
  <p>However, if I interrupt the program manually (CTRL-C), the thread is interrupted correctly : </p>
  
  <pre><code>1380542357.58
  ^C1380542361.49
  </code></pre>
  
  <p>Why does the thread interruption only occur after 10 seconds (and not 5) in the first example? </p>
  
  <p>I found an <a href="https://mail.python.org/pipermail/python-list/2004-November/293653.html" rel="nofollow">ancient thread n Python mailing list</a>, but it explains nearly nothing. </p>