Why does Python's Queue return an approximate size in qsize()?
multithreading, python
Solution
It is precisely because there are other threads accessing it. By the time you try to use the size you get back from qsize(), the queue could have changed. It would be better if the documentation read something like this:
Returns the size of the queue. Note that in a multi-threaded environment, the size can change at any time, making this only an approximation of the actual size.
Problem
In the doc of qsize() it says: Return the approximate size of the queue. Why can't it just return an exact size of this Queue? I understand the Queue may be accessed by multiple threads, but at the moment I call the function I think it's still possible to return the exact size of that moment.