def main(self): """Main loop.""" # activate the child (if we have one) yield Ipc.newComponent(*(self.childComponents())) done = False while not done: # check for requests to add/remove destinations while self.dataReady("configuration"): config = self.recv("configuration") if isinstance(config, addsink): self._addSink(config.sink, config.sinkbox, config.sinkcontrol) elif isinstance(config, removesink): self._delSink(config.sink, config.sinkbox, config.sinkcontrol) # pass anything received on 'inbox' inbox while self.dataReady(self.inboxname): data = self.recv(self.inboxname) self.send(data, "outbox") for (boxname, linkage) in self.outboxsinks.values(): self.send(data, boxname) # pass anything received on 'control' inbox while self.dataReady(self.controlname): msg = self.recv(self.controlname) self.send(msg, "signal") for (boxname, linkage) in self.signalsinks.values(): self.send(msg, boxname) # if we don't have a child component, we should shutdown in # response to msgs if not self.usingChild: if isinstance(msg, producerFinished) or isinstance( msg, shutdownMicroprocess): done = True # if we have a child, we'll shutdown when the child dies if self.usingChild: if self.childrenDone(): done = True # if we don't have a child, we know we'll be shutting down outselves # in response to a message received on 'control', so we can block # awaiting new data on inboxes if not self.usingChild: if not done: self.pause() yield 1 # unlink and cleanup on exit - unwire any destinations still connected for (sink, box) in self.outboxsinks.keys(): self._delSink(sink, box, None) for (sink, box) in self.signalsinks.keys(): self._delSink(sink, None, box)
def main(self): """Main loop.""" # activate the child (if we have one) yield Ipc.newComponent( *(self.childComponents()) ) done=False while not done: # check for requests to add/remove destinations while self.dataReady("configuration"): config = self.recv("configuration") if isinstance(config, addsink): self._addSink(config.sink, config.sinkbox, config.sinkcontrol) elif isinstance(config, removesink): self._delSink(config.sink, config.sinkbox, config.sinkcontrol) # pass anything received on 'inbox' inbox while self.dataReady(self.inboxname): data = self.recv(self.inboxname) self.send(data, "outbox") for (boxname, linkage) in self.outboxsinks.values(): self.send(data, boxname) # pass anything received on 'control' inbox while self.dataReady(self.controlname): msg = self.recv(self.controlname) self.send(msg, "signal") for (boxname, linkage) in self.signalsinks.values(): self.send(msg, boxname) # if we don't have a child component, we should shutdown in # response to msgs if not self.usingChild: if isinstance(msg, producerFinished) or isinstance(msg, shutdownMicroprocess): done = True # if we have a child, we'll shutdown when the child dies if self.usingChild: if self.childrenDone(): done=True # if we don't have a child, we know we'll be shutting down outselves # in response to a message received on 'control', so we can block # awaiting new data on inboxes if not self.usingChild: if not done: self.pause() yield 1 # unlink and cleanup on exit - unwire any destinations still connected for (sink, box) in self.outboxsinks.keys(): self._delSink(sink, box, None) for (sink, box) in self.signalsinks.keys(): self._delSink(sink, None, box)
def main(self): self.send(addsink(self, "inbox", "control"), "splitter_config") # activate the child yield Ipc.newComponent(*(self.childComponents())) # wait until all child component has terminated while not self.childrenDone(): # can't self.pause() as child may not immediately terminate after # sending/receiving final piece of data yield 1 # unplug from the splitter self.send(removesink(self, "inbox", "control"), "splitter_config") yield 1 # allow the msg to be sent self.postoffice.deregisterlinkage(thelinkage=self.pluglinkage)
def main(self): self.send( addsink( self, "inbox", "control" ), "splitter_config") # activate the child yield Ipc.newComponent( *(self.childComponents()) ) # wait until all child component has terminated while not self.childrenDone(): # can't self.pause() as child may not immediately terminate after # sending/receiving final piece of data yield 1 # unplug from the splitter self.send( removesink( self, "inbox", "control" ), "splitter_config") yield 1 # allow the msg to be sent self.postoffice.deregisterlinkage(thelinkage = self.pluglinkage)
def go(self): return Ipc.newComponent(*[c for c in self.childComponents()])