title: How to implement timeouts in a multithreaded program?
body: <p>I have this sample code:</p>
  
  <pre><code>import threading
  from Queue import Queue
  q = Queue(maxsize=0)
  def work(q):
      #do a job
  for line in file_of_100_line:
      q.put(line)
  nbThreads = 2
  for i in range(nbThreads):
      t = threading.Thread(target=work, args=(q))
      t.setDaemon(True)
      t.start()
  </code></pre>
  
  <p>and I wanted to make a thread end if the threads takes more than "x" seconds to execute. How could I do that with multithreading? Thanks</p>