473,503 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iterator interface for Queue?

Is there any reason Queue shouldn't have an iterator interface?
I.e. instead of

while True:
item = work_queue.get()
if item is quit_sentinel:
# put sentinel back so other readers can find it
work_queue.put(quit_sentinel)
break
process(item)

with accompanying hair on the other side to create and send a sentinel,
you'd just say:

for item in work_queue:
process(item)

You'd still need hair at the writing end to tell the readers when to
finish, either by directly inserting a sentinel or with
"work_queue.done()" or something like that.
Apr 8 '07 #1
1 4491
On Apr 7, 11:40 pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
Is there any reason Queue shouldn't have an iterator interface?
I.e. instead of

while True:
item = work_queue.get()
if item is quit_sentinel:
# put sentinel back so other readers can find it
work_queue.put(quit_sentinel)
break
process(item)
It's almost equal to:

for item in iter(work_queue.get, quit_sentinel):
process(item)

except that it doesn't keep the quit sentinel in the queue. But that's
a personal preference, I usually put as many quit sentinels in a queue
as many consumers.

-- Leo

Apr 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1696
by: Helmut Jarausch | last post by:
Hi, I cannot find out what I miss with my iterator example. I have a linked list class Queue which has a 'Head' attribute and the following def __iter__(self): if self.Head == None: raise...
38
3638
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
14
4854
by: shawnk | last post by:
I searched the net to see if other developers have been looking for a writable iterator in C#. I found much discussion and thus this post. Currently (C# 2) you can not pass ref and out arguments...
0
2664
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
16
2555
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid...
3
2541
by: raan | last post by:
Is iterators singleton? I am accessing a map through wrapper functions to it; that allow me to access the contents of the map as CUnit &unit = hash.getFirstunit(); while(hash.hasMoreunits())...
1
2756
by: Scott Gifford | last post by:
Hello, I'm working on an providing an iterator interface to a database. The basic thing I'm trying to accomplish is to have my iterator read rows from the database and return constructed...
7
22664
by: Donos | last post by:
Hello I have a Queue which is declared as, std::queue<unsigned charm_Queue; I push data into this queue. Now i want to take the data out of this queue using Iterator.
0
1230
by: vaclavpich | last post by:
Hi all, I needed a priority queue but I couldn't use stl. So I wrote my priority queue. But I'm not sure that my implementation is good. I want to know your opinion : ...
0
7205
marktang
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,...
0
7349
jinu1996
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...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5022
isladogs
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...
0
4688
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...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
399
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.