[Python-3000] Useless methods in Queue module

Jeffrey Yasskin jyasskin at gmail.com
Tue Jan 15 07:30:35 CET 2008


On Jan 14, 2008 6:31 PM, Mike Klaas <mike.klaas at gmail.com> wrote:
> On 14-Jan-08, at 5:49 PM, Jeffrey Yasskin wrote:
>
> > On Jan 14, 2008 2:55 PM, Mike Klaas <mike.klaas at gmail.com> wrote:
>
> >> This is a misleading name.  The number returned from qsize() [not
> >> size
> >> ()] is perfectly reliable, in the sense that it is the exact size of
> >> the queue at some instant in time.
> >
> > No, you're wrong. In CPython's implementation, it's likely that qsize
> > is implemented by locking the structure and reading a size field,
>
> It isn't likely, it is.  It is also implemented as such in all
> mainstream python interpreters (ironpython, jython), since they use
> CPython's pure-python implementation.

Yes, I was thinking solely about the API, while everyone else is
thinking (correctly) about the implementations we actually have. Sorry
for being needlessly confrontational.

> I grant that it is theoretically possible to implement Queue.Queue's
> full interface with a data structure in which qsize() is never a
> consistent length of the index at a given time, even if such a
> structure may not yet exist.
>
> > Furthermore, it's misleading to think of even a locked
> > implementation's result as reliable. Ignoring problems with
> > simultaneity in the presence of threads, the "true" value could easily
> > have changed by the time qsize returns. And if it returns a value
> > that's not accurate, that can hardly be described as reliable. It
> > really is returning an estimate of the size, suitable only for use in
> > performance optimizations where you're prepared to handle it sometimes
> > being wildly wrong.
>
> In some usage patterns it is thread-unsafe.  Whether this means that
> the method itself is "unreliable" is a battle likely not worth
> getting in to.
>
> Thanks for the interesting reference,
> -Mike
>



-- 
Namasté,
Jeffrey Yasskin
http://jeffrey.yasskin.info/

"Religion is an improper response to the Divine." — "Skinny Legs and
All", by Tom Robbins


More information about the Python-3000 mailing list