[New-bugs-announce] [issue26958] Suggestion to imporve queue.full reliability

Sudharsan R report at bugs.python.org
Wed May 4 15:37:12 EDT 2016

New submission from Sudharsan R:

I was browsing through the code for queue.full and queue.put methods. The queue.full method claims it is not a reliable one. But, the same internal implementation - _qsize is used for put as well as full. "put" is thread safe and reliable and "full" is not.
Why can't the full method acquire self.not_full instead of self.mutex, which will make both of the methods accurate at that instance of time?

    def full(self):
        """Return True if the queue is full, False otherwise (not reliable!)."""
        n = 0 < self.maxsize == self._qsize()
        return n
    def put(self, item, block=True, timeout=None):
        """Put an item into the queue.

        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until a free slot is available. If 'timeout' is
        a positive number, it blocks at most 'timeout' seconds and raises
        the Full exception if no free slot was available within that time.
        Otherwise ('block' is false), put an item on the queue if a free slot
        is immediately available, else raise the Full exception ('timeout'
        is ignored in that case).
            if self.maxsize > 0:
                if not block:
                    if self._qsize() == self.maxsize:
                        raise Full

messages: 264851
nosy: Sudharsan R
priority: normal
severity: normal
status: open
title: Suggestion to imporve queue.full reliability
type: behavior
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list