Add timeout argument to python's Queue.join()

Viewed 9085

I want to be able to join() the Queue class but timeouting after some time if the call hasn't returned yet. What is the best way to do it? Is it possible to do it by subclassing queue\using metaclass?

4 Answers

As I tried to implement the accepted answer, it seems that all_tasks_done is not defined anymore. A quick solution is to use the timeout of the wait() function called in JoinableQueue.join.

For example overriding the join function in a subclass of JoinableQueue will add a 15s timeout on the waiting operation :

def join(self):
    with self._cond:
        if not self._unfinished_tasks._semlock._is_zero():
            self._cond.wait(15)
Related