According to the Python 2.7 docs, Queue.qsize isn't dependable, and help(Queue.Queue.qsize) says that it isn't reliable.  Is there a particular implementation issue I am not aware of?
P.S.  I am aware that Queue.Queue.qsize uses mutexes, and that the size of the Queue may change between when I call the method and when I get the result, but for single-threaded applications, are Queues safe?
Message from help(Queue.Queue.qsize):
>>> help(Queue.Queue.qsize)
Help on method qsize in module Queue:
qsize(self) unbound Queue.Queue method
    Return the approximate size of the queue (not reliable!).
>>> 
                The method qsize() returns the number of elements present in a queue.
To get the length of a queue in Python:Use the len() function to get the length of a deque object. Use the qsize() method to get the length of a queue object.
Queue.Queue.qsize works fine in a single-threaded application (and even in a multi-threaded application for many applications of its purpose). You simply can't use it to reliably determine whether a call to put or get will block.
Note that if you don't need concurrency, collections.deque is faster than Queue.Queue. Or, if performance isn't critical, you could go the simple route and just use regular lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With