Queue qsize = unreliable?

Grant Edwards grante at visi.com
Fri Aug 6 18:14:38 CEST 2004

On 2004-08-06, Peter Hansen <peter at engcorp.com> wrote:

>> I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
>>      |  qsize(self)
>>      |      Return the approximate size of the queue (not reliable!).
>> Any thoughts on why this is unreliable (and more curiously, why it would
>> be put in there as an unreliable function?) Rather than roll my own
>> threaded fifo class, it would seem prudent to use Python's built-in
>> Queue but the warning signs on a rather necessary function seem curious.
> (Why do you think this function is necessary?  It's probably
> rare to really need it, except perhaps during debugging... )
> Anyway, the reason it's called "unreliable", though the term
> "inaccurate" might be more correct, is because while you are
> getting the size of the queue, it might be updated such that
> the new size is one or more fewer or larger than the value
> that is about to be returned to you.

I don't think that's any reason to call the function either
unreliable or inaccurate.  If you're operating in a
multi-threaded environment, such a statement is trivially true
about anything that accesses shared data.

For example: time.time() needs a disclaimer that it is
unreliable, since the result it returns is incorrect by the
time you get around to using it...

Grant Edwards                   grante             Yow!  Spreading peanut
                                  at               butter reminds me of
                               visi.com            opera!! I wonder why?

More information about the Python-list mailing list