title: Timeout function using threading in python does not work
body: <p>I have found a code creating a timeout function <a href="http://code.activestate.com/recipes/473878-timeout-function-using-threading/" rel="noreferrer">here</a>, which does not seem to work. The complete test code is below:</p>
  
  <pre><code>def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
      import threading
      class InterruptableThread(threading.Thread):
          def __init__(self):
              threading.Thread.__init__(self)
              self.result = None
  
          def run(self):
              try:
                  self.result = func(*args, **kwargs)
              except:
                  self.result = default
  
      it = InterruptableThread()
      it.start()
      it.join(timeout_duration)
      if it.isAlive():
          return default
      else:
          return it.result
  
  
  def foo():
      while True:
          pass
  
  timeout(foo,timeout_duration=3)
  </code></pre>
  
  <p>Expected behavior: code ends within 3 seconds. Where is the problem?</p>