Queue peek?

Raymond Hettinger python at rcn.com
Tue Mar 2 13:18:54 EST 2010


On Mar 2, 8:29 am, Veloz <michaelve... at gmail.com> 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)
Raymond


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /