I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
| qsize(self)
| Return the approximate size of the queue (not reliable!).
Any thoughts on why this is unreliable (and more curiously, why it would
be put in there as an unreliable function?) Rather than roll my own
threaded fifo class, it would seem prudent to use Python's built-in
Queue but the warning signs on a rather necessary function seem curious.
Jamie 4 4700
"James R. Saker Jr." <js****@america nrelay.com> writes: I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
| qsize(self) | Return the approximate size of the queue (not reliable!).
Any thoughts on why this is unreliable (and more curiously, why it would be put in there as an unreliable function?) Rather than roll my own threaded fifo class, it would seem prudent to use Python's built-in Queue but the warning signs on a rather necessary function seem curious.
Well, by the time you examine (or even get!) the answer, it might be
wrong. Kinda hard to avoid this in the setting of multiple threads!
Cheers,
mwh
--
All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore,
if you can't get them together again, there must be a reason. By all
means, do not use a hammer. -- IBM maintenance manual, 1925
James R. Saker Jr. wrote: I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
| qsize(self) | Return the approximate size of the queue (not reliable!).
Any thoughts on why this is unreliable (and more curiously, why it would be put in there as an unreliable function?) Rather than roll my own threaded fifo class, it would seem prudent to use Python's built-in Queue but the warning signs on a rather necessary function seem curious.
(Why do you think this function is necessary? It's probably
rare to really need it, except perhaps during debugging... )
Anyway, the reason it's called "unreliable ", though the term
"inaccurate " might be more correct, is because while you are
getting the size of the queue, it might be updated such that
the new size is one or more fewer or larger than the value
that is about to be returned to you. In effect, the value is
guaranteed accurate only for the precise instant in time, now
passed, that it was determined, but by the time the calling
routine actually sees the value the size could be anything.
Note also the latest docs at docs.python.org , which state the
case a little more clearly.
"""Return the approximate size of the queue. Because of
multithreading semantics, this number is not reliable. """
-Peter
On 2004-08-06, Peter Hansen <pe***@engcorp. com> wrote: I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
| qsize(self) | Return the approximate size of the queue (not reliable!).
Any thoughts on why this is unreliable (and more curiously, why it would be put in there as an unreliable function?) Rather than roll my own threaded fifo class, it would seem prudent to use Python's built-in Queue but the warning signs on a rather necessary function seem curious.
(Why do you think this function is necessary? It's probably rare to really need it, except perhaps during debugging... )
Anyway, the reason it's called "unreliable ", though the term "inaccurate " might be more correct, is because while you are getting the size of the queue, it might be updated such that the new size is one or more fewer or larger than the value that is about to be returned to you.
I don't think that's any reason to call the function either
unreliable or inaccurate. If you're operating in a
multi-threaded environment, such a statement is trivially true
about anything that accesses shared data.
For example: time.time() needs a disclaimer that it is
unreliable, since the result it returns is incorrect by the
time you get around to using it...
--
Grant Edwards grante Yow! Spreading peanut
at butter reminds me of
visi.com opera!! I wonder why?
In article <ze************ ********@powerg ate.ca>,
Peter Hansen <pe***@engcorp. com> wrote: James R. Saker Jr. wrote:
I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable:
| qsize(self) | Return the approximate size of the queue (not reliable!).
Any thoughts on why this is unreliable (and more curiously, why it would be put in there as an unreliable function?) Rather than roll my own threaded fifo class, it would seem prudent to use Python's built-in Queue but the warning signs on a rather necessary function seem curious.
(Why do you think this function is necessary? It's probably rare to really need it, except perhaps during debugging... )
Anyway, the reason it's called "unreliable ", though the term "inaccurate " might be more correct, is because while you are getting the size of the queue, it might be updated such that the new size is one or more fewer or larger than the value that is about to be returned to you. In effect, the value is guaranteed accurate only for the precise instant in time, now passed, that it was determined, but by the time the calling routine actually sees the value the size could be anything.
Note also the latest docs at docs.python.org , which state the case a little more clearly.
"""Return the approximate size of the queue. Because of multithreadi ng semantics, this number is not reliable. """
And an inaccurate number is still quite usable. If you are
the only one reading from a queue, you know that the number
is at least as large as indicated. If you read from multiple
queues, you can use the indicated number to pick which queue
to handle first.
This allows you to do pollling and fair scheduling and some other
neat tricks.
The same sort of tricks works for writers as well.
Jacob Hallén
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bart Nessux |
last post by:
How can one view the contents of a queue? I'd like to verify that the
queue has the same number of objects as the list that has been put into
it. Also, should one think of a queue as static or dynamic (on the put
side)? Do you put stuff in it once and then get from it until it's empty
or do you put stuff in it a bit at a time? Or, can you do...
|
by: phil |
last post by:
And sorry I got ticked, frustrating week
>And I could help more, being fairly experienced with
>threading issues and race conditions and such, but
>as I tried to indicate in the first place, you've
>provided next to no useful (IMHO) information to
>let anyone help you more than this
This is about 5% of the code.
Uses no locks.
|
by: spinner |
last post by:
---------------------------------------------
A two parter newbie question I am afraid.
Am I right in thinking that using something like ...
item = a_queue.get()
print item
will not print 'item' unless or until there is an item in the queue to
|
by: Kimmo Laine |
last post by:
Hello,
i have the following C# app, where i send messages to MSMQ:
---
private void button1_Click(object sender, System.EventArgs e) {
const string QNAME = @".\private$\Deltest";
MessageQueue mq = null;
|
by: Arnie |
last post by:
We have noticed that the FileSystemWatcher is not reliable. It is not easily
repeatable but sometime it fails to catch file system changes. When it gets
into this state it doesn't recover unless a reboot is done.
The problem is only seen when multiple files are copied to the system in
quick succession. Once the watcher misses a file *any*...
| |
by: Jeffrey Barish |
last post by:
Several methods in Queue.Queue have warnings in their doc strings that they
are not reliable (e.g., qsize). I note that the code in all these methods
is bracketed with lock acquire/release. These locks are intended to
protect the enclosed code from collisions with other threads. I am
wondering whether I understand correctly that the reason...
|
by: tikcireviva |
last post by:
Hi Guys,
I've done a mulithread queue implementation on stl<queue>, my
developement environment is on VC6 as well as FC3. Let's talks about
the win32 side.
The suspected memory leak is find after I've run through my unit test
cases.
Test Case:
|
by: Gabriel Rossetti |
last post by:
Hello,
I'm having some trouble with the Queue class, for some reason, if I do
this (ch == ) :
q = Queue.Queue(0)
repr(ch)
q.put(ch, True)
len(q.queue)
|
by: redbaron |
last post by:
I run into problem with queue from multiprocessing. Even if I
queue.qsize() != 0 queue.get() still blocks and queue.get_nowait()
raises Emtpy error.
I'm unable to cut my big part to small test case, because smaller test
case similair to my real app by design is works. In what conditions is
it possible?
while qresult.qsize():
result =...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |