Queue qsize = unreliable?

Ames Andreas (MPA/DF) Andreas.Ames at tenovis.com
Fri Aug 6 18:10:28 CEST 2004


Tim Peters wrote:

> There's no use case I know of where knowing "the exact current size"
> is necessary, except inside the implementation of Queue (where it
> can know it, but at the expense of locking out all other threads for
> as long as it takes to compute the result).

I've got one:  If you have the special situation that there is only a
single consumer with potentially multiple suppliers (or similarly if
you have it the other way around), you could implement the consumer in
a non-blocking manner.  Then it's not that important to get "the exact
current size" which would still be unreliable but it is important to
have a reliable empty method (or rather !empty() and full() are
reliable in this situation).  I think Queue is reliable in this
respect but to get it additionally non-blocking you will have to roll
your own queue.



More information about the Python-list mailing list