def shutdown(self): """Sends terminatory signals to the wrapped component, and shut down the componentWrapper. will warn if the shutdown took too long to confirm in action.""" # TODO - what if the wrapped component has no control box? if self.alive: self.put(Ipc.shutdown(), "control") # legacy support. self.put(Ipc.producerFinished(), "control") # some components only honour this one self.put(Ipc.shutdownMicroprocess(), "control") # should be last, this is what we honour else: raise AttributeError("shutdown was previously called, or we were never activated.") self.inputComponent.isDead.wait(1) if not self.inputComponent.isDead.isSet(): # we timed out instead of someone else setting the flag warnings.warn("Timed out waiting on shutdown confirmation, may not be dead.") self.alive = False
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): not_done = True i = 0 ilist = [] while not_done: i += 1 print str(i) if not i % 3: ilist.append(str(i)) self.log.writelines(ilist) ilist = [] else: ilist.append(str(i)) if i == 50: self.log.writelines(ilist) self.log.flush() not_done = False yield 1 self.send(Ipc.shutdownMicroprocess(), 'signal') self.send(Ipc.shutdownMicroprocess(), 'signal-logger')
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()])