[issue42420] queue.Queue().join() add a timeout option

Gerhard van Andel report at bugs.python.org
Fri Nov 20 15:55:27 EST 2020


New submission from Gerhard van Andel <vananger93 at gmail.com>:

class Queue:

    def join():
        ...

# Can we add a timeout option to the join method on queue.Queue 

    def join(timeout=None):
        '''Blocks until all items in the Queue have been gotten and processed.

        The count of unfinished tasks goes up whenever an item is added to the
        queue. The count goes down whenever a consumer thread calls task_done()
        to indicate the item was retrieved and all work on it is complete. If
        'timeout' is a non-negative number, it blocks at most 'timeout' seconds
        and raises the Full exception if no free slot was available within that
        time.

        When the count of unfinished tasks drops to zero, join() unblocks.
        '''
        if timeout and timeout < 0:
            raise ValueError("'timeout' must be a non-negative number")
        with self.all_tasks_done:
            while self.unfinished_tasks:
                self.all_tasks_done.wait(timeout)

----------
components: Library (Lib)
messages: 381506
nosy: vananger93
priority: normal
severity: normal
status: open
title: queue.Queue().join() add a timeout option
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42420>
_______________________________________


More information about the Python-bugs-list mailing list