[Stackless] Queues
Benjamin Buco
fiatetdeusetlux at yahoo.com
Tue Apr 4 03:34:32 CEST 2006
This is an implementation for what amounts to a queue or buffered channel. Any suggestions, advice, criticism before I post this to the wiki would be appreciated. Its probably not the cleanest solution but at least it's pretty. Also anyone have any objections to me restoring the link to the channels page to the main stackless page?
import stackless
class Queue(stackless.channel):
def uselesstasklet(self,value):
return stackless.channel.send(self, value)
def send(self, value, wait=False):
useless = stackless.tasklet(self.uselesstasklet)(value)
stackless.schedule(useless)
return None
def testQueue():
print
print "testQueue"
print "--------------------"
def recv(ch, name):
print "Started recv<%s>" % (name,)
print "recv<%s>: %r" % (name, ch.receive())
ch = Queue()
# Queues are nonblocking on sends when there are no receivers
ch.send("Primary Entry")
ch.send("Secondary Entry")
for name in "ABCD":
task = stackless.tasklet(recv)(ch, name)
task.run()
ch.send("Third Entry")
ch.send("Fourth Entry")
print
testQueue()
Thanks guys.
Benjamin Buco
MCSE:Security
IT Instructor
TechSkills Cincinnati
---------------------------------
Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20060403/963bd41c/attachment.htm>
-------------- next part --------------
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list