python queue get size, use qsize() or len()?

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?

Best answer

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.