title: python: using threading , apply thread timeout
body: <p>I'm using threading library in a  multithreading script. I want to implement a timeout on the thread. Thus, if the thread hasn't returned <code>task_done</code> after a specified amount of time, it should come out of the function and return <code>task_done</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>def create_workers():
      for _ in range(NUMBER_OF_THREADS):
          t = threading.Thread(target=work)
          t.daemon = True
          t.start()
  
  
  def create_jobs():
      for d in Date_set :
          queue.put(d)
      queue.join()
      scrape()
  
  
  def scrape_page(thread_name, page_url):
      print(thread_name + ' now working on ' + page_url)
      get_active_urls_perDay(session=s,Date=page_url,County=Cty, courtSystem=CS, PT=P)
  
  
  def work():
      while True:
          url = queue.get()
          scrape_page(threading.current_thread().name, url)
          Date_set.remove(url)
          print str(len(Date_set)) + " days more to go!"
          print "Number of threads active", threading.activeCount()
          queue.task_done()
  
  
  def scrape():
      queued_links = Date_set
      if len(queued_links) &gt; 0:
          print(str(len(queued_links)) + ' days in the queue')
          create_jobs()
  </code></pre>
  
  <p>In the <code>work</code> function, I want to implement a timeout on the thread.
  Otherwise the code runs fine, but the threads which haven't returned <code>task_done</code> halt the code and it keeps waiting for them to return.</p>