Howto wait for multiple queues (Queue.py)?
Dennis Lee Bieber
wlfraed at ix.netcom.com
Thu Nov 21 20:40:04 EST 2002
Andreas Ames fed this fish to the penguins on Thursday 21 November 2002
02:01 am:
>
> I think this would be another possibility which would probably look
> similar to alternative 3 in my post. My main concern is the
> performance of this approach as the queue is one of *the* central
> concepts in my server.
>
I suspect Alex Martelli (sp?) has the proper argument, but may have
obscured it some.
You seem to be asking for something similar to Ada's selective
rendezvous (not actual Ada shown below):
Accept EventQueue()
....
or accept CommandQueue()
....
Problem with Ada is that those accepts are specific to the task
(thread), and not shared by a pool.
In pseudo-Python you seem to want:
while 1:
c = Command.get_nowait()
e = Event.get_nowait()
if c:
#command process
elif e:
#event process
WITHOUT the busy wait.
So... Rather than use two queues, on for each type of data, why not
pass the data type as the first item of the entry?
while 1:
d = CEQueue.get() #use the blocking mode
if d[0] == "COMMAND":
#command process
elif d[0] == "EVENT":
#event process
All the "writers" use:
CEQueue.put(("COMMAND, data))
or
CEQueue.put(("EVENT, data))
IOWs; just take your current queue data, and make a tuple with that
data AND a determinant for the type of data.
Ada would need the selective accept because of its strict static type
checking. Python Queues can accept any data with each entry.
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list