From: Floris Bruynooghe on
On Mar 2, 6:18 pm, Raymond Hettinger <pyt...(a)> wrote:
> On Mar 2, 8:29 am, Veloz <michaelve...(a)> wrote:
> > Hi all
> > I'm looking for a queue that I can use with multiprocessing, which has
> > a peek method.
> > I've seen some discussion about queue.peek but don't see anything in
> > the docs about it.
> > Does python have a queue class with peek semantics?
> Am curious about your use case?  Why peek at something
> that could be gone by the time you want to use it.
>   val = q.peek()
>   if something_i_want(val):
>        v2 = q.get()         # this could be different than val
> Wouldn't it be better to just get() the value and return if you don't
> need it?
>   val = q.peek()
>   if not something_i_want(val):
>       q.put(val)

What I have found myself wanting when thinking of this pattern is a
"q.put_at_front_of_queue(val)" method. I've never actually used this
because of not having such a method. Not that it's that much of an
issue as I've never been completely stuck and usually found a way to
solve whatever I was trying to do without peeking, which could be
argued as a better design in the first place. I was just wondering if
other people ever missed the "q.put_at_front_of_queue()" method or if
it is just me.


PS: assuming "val = q.get()" on the first line
From: Gregory Ewing on
Floris Bruynooghe wrote:
> I was just wondering if
> other people ever missed the "q.put_at_front_of_queue()" method or if
> it is just me.

Sounds like you don't want a queue, but a stack. Or
maybe a double-ended queue.

From: Aahz on
In article <58f61382-ac79-46fb-8612-a3c9fde297dc(a)>,
Veloz <michaelveloz(a)> wrote:
>The "peek" parts comes in when the user comes back later to see if
>their report has done. That is, in my page controller logic, I'd like
>to look through the complete queue and see if the specific report has
>been finished (I could tell by matching up the ID of the original
>request to the ID in the completed queue). If there was an item in the
>queue matching the ID, it would be removed.

Here's the question: what happens when the user refreshes the "report
done" page? The problem with the way you're doing it is that checking
for report done is a one-shot operation. You probably want to use a
database to cache this and have some kind of cache expiration.
Aahz (aahz(a) <*>

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer