class PathologicalExample(Axon.Component.component):
logfile = "test.log"
...
def main(self):
try:
while True:
for message in self.Inbox():
self.process(message)
if self.dataReady("control"):
raise GotShutdownMessage()
if not self.anyReady():
self.pause()
yield 1
except GotShutdownMessage:
self.send(self.recv("control"), "signal")
yield 1
return
self.send(Axon.Ipc.producerFinished(), "signal")
yield 1
In that example, the only part that is specific to the component is self.process. While PureTransformer exists, as an approach it's incomplete, and doesn't support threaded components. Having a better "Sugar" component to allow these sorts of components to be OK, as well as components that look like this:
class SerialSender(Axon.ThreadedComponent.threadedcomponent):
""" Derived from kamaelia.git/Sketches/MPS/ArduinoRelated/ArdCube.py#SerialIO"""
serialport = '/dev/ttyUSB0'
baudrate = 9600
def main(self): # FIXME: Shutdown for this component does not play nicely with others
ser = serial.Serial(self.serialport, self.baudrate)
while True:
for msg in self.Inbox("inbox"):
ser.write(str(msg))
time.sleep(0.01)
-- ie to enable this sort of component to play nicely - would be very nice/useful. Additionally, this could act as bridging code to the kamaelia rewrite Guild that should be starting at some point.