[Stackless] Thought it is easy to right tasks continually waiting for messages
TOUMAN
touman at btinternet.com
Sat Jan 2 12:04:12 CET 2010
Hi I am a newbi to stakless. I have read the documentaion specially the piece by grant olson.
I want to create three tasks which are continually waiting for messages and don not die until they recieve the "exit" message. I have written the code below:
import os, sys
import stackless
import math
global _unit_A, _unit_B, _unit_C
_unit_A = stackless.channel()
_unit_B = stackless.channel()
_unit_C = stackless.channel()
class units:
def __init__(self,channel,name):
self.ch = channel
self.name = name
stackless.tasklet(self.process)()
def process(self):
print self.name,"Unit running"
while True:
msg = self.ch.receive()
if msg == "exit":
return
print self.name,":",msg
stackless.schedule()
def testit():
print "Testing the parallel tasks"
units(_unit_A,"unit A")
units(_unit_B,"unit B")
units(_unit_C,"unit C")
msg = "Msg from unit A who says hello"
_unit_B.send(msg)
stackless.run()
testit()
But when I run it, it runs through all tasks once and the program finishes and I get this.
c:\>
Testing the parallel tasks
unit A Unit running
unit B Unit running
unit B : Msg from unit A who says hello
unit C Unit running
c:\>
I am sure it must be something simple, but cant figure it out. Does anybody know what is happening here and what I am doing wrong?
cheers
tomcat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20100102/edc488c0/attachment.htm>
More information about the Stackless
mailing list