This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sudharsan R
Recipients Sudharsan R
Date 2016-05-04.19:37:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1462390632.09.0.248563716558.issue26958@psf.upfronthosting.co.za>
In-reply-to
Content
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!)."""
        self.mutex.acquire()
        n = 0 < self.maxsize == self._qsize()
        self.mutex.release()
        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).
        """
        self.not_full.acquire()
        try:
            if self.maxsize > 0:
                if not block:
                    if self._qsize() == self.maxsize:
                        raise Full
History
Date User Action Args
2016-05-04 19:37:12Sudharsan Rsetrecipients: + Sudharsan R
2016-05-04 19:37:12Sudharsan Rsetmessageid: <1462390632.09.0.248563716558.issue26958@psf.upfronthosting.co.za>
2016-05-04 19:37:12Sudharsan Rlinkissue26958 messages
2016-05-04 19:37:11Sudharsan Rcreate