Hi Matt & Michael, The yield thing was the exact problem. Thank you! Guess we missed it in the documentation.
Joesan On Aug 10, 7:25 pm, Michael Sparks <[email protected]> wrote: > On Aug 10, 11:11 pm, Joesan <[email protected]> wrote: > > > We started working with kamaelia recently at work and we're having > > trouble right now working with threadedcomponents. > ... > > The new component gets created just fine but for some reason > > it seems it's main function is never actually called. > > At a random guess, does your main method contain a yield ? (This is > the > most common cause of this problem) > > Threadedcomponents do NOT have a generator as the main method. (I've > been > wondering if this was a good decision, but it's a little late now) > > So, for example this will cause a message to be emitted once per > second: > > import time > import Axon > from Kamaelia.Util.Console import ConsoleEchoer > from Kamaelia.Chassis.Pipeline import Pipeline > > class Prodder(Axon.Threadedcomponent.threadedcomponent): > def main(self): > while not self.dataReady("control"): > time.sleep(1) > self.send("ping", "outbox") > self.send(self.recv("control"), "signal") > > Pipeline( Prodder(), ConsoleEchoer()).run() > > However this version will not work because main is a generator not a > regular method. > > class Prodder(Axon.Threadedcomponent.threadedcomponent): > def main(self): > while not self.dataReady("control"): > time.sleep(1) > self.send("ping", "outbox") > yield 1 > self.send(self.recv("control"), "signal") > > > PS - This may not have any effect on anything, but we're not using > > graphline right now and are calling link several times to actually > > link together the mailboxes of various components. Could this keep > > the threadedcomponent's main from starting? > > Almost certainly not - I would expect that the issue is that the main > method is a generator. (I've often wondered in recent months whether > this was the right decision) > > The reason you'd see this behaviour incidentally is that under the > hood > what actually happens is the main method is used as the new thread > of control inside the thread. If it's a generator method this would > simply create the generator (inside the new thread) and then exit. > Hence confusion. > > Hopefully that helps! (If it doesn't please post a fragment showing > the confusing behaviour) > > Michael. -- You received this message because you are subscribed to the Google Groups "kamaelia" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/kamaelia?hl=en.
