I was working through their tutorial:
> * http://kamaelia.sourceforge.net/MiniAxon/
Chapter 5 claims the output should be:
Hello World 2
Hello World 3
...
Hello World 97
Hello World 98
But mine outputs only:
Hello World 2
(no further output)
I can see in Pythonwin's debugger that p.boxes['outbox'] fills up with
the hundred or so messages intended for display, but they never get
displayed. I suspect an indentation problem, but I can't spot it, even
stepping through in the debugger.
Alan
#=============================================
class microprocess(object):
def __init__(self):
super(microprocess, self).__init__()
def main(self):
yield 1
#=============================================
class scheduler(microprocess):
def __init__(self):
super(scheduler, self).__init__()
self.active = []
self.newqueue = []
def main(self):
for x in xrange(100):
for current in self.active:
yield 1
try:
result = current.next()
if result is not -1:
self.newqueue.append(current)
except StopIteration:
pass
self.active = self.newqueue
self.newqueue = []
def activateMicroprocess(self, someprocess):
microthread = someprocess.main()
self.newqueue.append(microthread)
#=============================================
class postman(microprocess):
def __init__(self, source, sourcebox, sink, sinkbox):
super(postman, self).__init__()
self.source = source
self.sourcebox = sourcebox
self.sink = sink
self.sinkbox = sinkbox
def main(self):
yield 1
if self.source.dataReady(self.sourcebox):
postdata = self.source.recv(self.sourcebox)
self.sink.send(postdata, self.sinkbox)
#=============================================
class component(microprocess):
def __init__(self):
super(component, self).__init__()
self.boxes = { 'inbox': [], 'outbox': [] }
def send(self, value, boxname):
self.boxes[boxname].append(value)
def recv(self, boxname):
return self.boxes[boxname].pop(0)
def dataReady(self, boxname):
return len( self.boxes[boxname] )
#=============================================
class Producer(component):
def __init__(self, message):
super(Producer, self).__init__()
self.message = message
def main(self):
while 1:
yield 1
self.send(self.message, "outbox")
#=============================================
class Consumer(component):
#~ def __init__(self, tag):
#~ super(Consumer, self).__init__()
def main(self):
count = 0
while 1:
yield 1
count += 1
if self.dataReady("inbox"):
data = self.recv("inbox")
print data, count
p = Producer("Hello World")
c = Consumer()
postie = postman(p, "outbox", c, "inbox")
myscheduler = scheduler()
myscheduler.activateMicroprocess(p)
myscheduler.activateMicroprocess(c)
myscheduler.activateMicroprocess(postie)
for _ in myscheduler.main():
pass
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor