I've seen instances where qsize() and len() has been used to compute the size of the queue. What is the distinction between the two?

1

2 Answers

For most containers, you'll want len, but Queue.Queue doesn't actually support len. This may be because it's old or because getting the length of a queue in a multithreaded environment isn't particularly useful. In any case, if you want the (approximate) size of a Queue, you want qsize.

3

queue.qsize() doesn't return the number of bytes in the queue. It returns the number of "things" placed in the queue.

If you put 5 byte-arrays of 100 bytes in the queue, the qsize() will be 5, not 500.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy