[issue34180] bool(Q) always return True for a priority queue Q

Tim Peters report at bugs.python.org
Sun Jul 22 14:37:48 EDT 2018


Tim Peters <tim at python.org> added the comment:

I'm sure Guido designed the API to discourage subtly bug-ridden code relying on the mistaken belief that it _can_ know the queue's current size.  In the general multi-threaded context Queue is intended to be used, the only thing `.qsize()`'s caller can know is that the queue _had_ the returned size at some time in the past.  It can't know what the size is at the time the returned value is used.

Note that the docstrings still say that the `.empty()` and `.full()` methods are "likely to be removed at some point".  The only surprise to me is that `.qsize()` doesn't also say that.  As is, I still see race-ridden code on StackOverflow from time to time using `.qsize()`.  There are already plenty of warnings about that in the docs.

----------
nosy: +tim.peters

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34180>
_______________________________________


More information about the Python-bugs-list mailing list