On Jan 14, 2008 6:31 PM, Mike Klaas <[EMAIL PROTECTED]> wrote: > On 14-Jan-08, at 5:49 PM, Jeffrey Yasskin wrote: > > > On Jan 14, 2008 2:55 PM, Mike Klaas <[EMAIL PROTECTED]> 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 _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com