def join_with_timeout(q, timeout=2):
 q.all_tasks_done.acquire()
 try:
  endtime = (time() + timeout)
  while q.unfinished_tasks:
   remaining = (endtime - time())
   if (remaining <= 0.0):
    raise RuntimeError('Waiting for queue to clear timed out')
   q.all_tasks_done.wait(remaining)
 finally:
  q.all_tasks_done.release()

def join_with_timeout ( q , timeout = 2 ) : q . all_tasks_done . acquire ( ) try : endtime = ( time ( ) + timeout ) while q . unfinished_tasks : remaining = ( endtime - time ( ) ) if ( remaining <= 0.0 ) : raise RuntimeError ( 'Waiting for queue to clear timed out' ) q . all_tasks_done . wait ( remaining ) finally : q . all_tasks_done . release ( )
join the queue q with a specified timeout .