def run(self): """ Main Loop """ ## subscribe this agent to all ## the messages of the switch. ## Later on when the agent starts receiving messages, ## it will signal which 'message types' are of interest. mswitch.subscribe(self.id, self.iq, self.isq) getattr(self, "beforeRun")() print "Agent(%s) (%s) starting" % (self.agent_name, self.id) self._pub("__agent__", self.agent_name, self.id, "started") quit = False while not self.quit and not quit: quit = process_queues(self.halting, self, self.agent_name, self.id, self.mmap, self.responsesInterest, self.iq, self.isq, message_processor) self.loop() self.beforeQuit() ##self._pub("__agent__", self.agent_name, self.id, "stop") print "Agent(%s) (%s) ending" % (self.agent_name, self.id)
def run(self): """ Main Loop """ ## subscribe this agent to all ## the messages of the switch. ## Later on when the agent starts receiving messages, ## it will signal which 'message types' are of interest. mswitch.subscribe(self.id, self.iq, self.isq) getattr(self, "beforeRun")() print "Agent(%s) (%s) starting" % (self.agent_name, self.id) self._pub("__agent__", self.agent_name, self.id, "started") quit=False while not self.quit and not quit: quit=process_queues(self.halting, self, self.agent_name, self.id, self.mmap, self.responsesInterest, self.iq, self.isq, message_processor) self.loop() self.beforeQuit() ##self._pub("__agent__", self.agent_name, self.id, "stop") print "Agent(%s) (%s) ending" % (self.agent_name, self.id)
def run(self): """ Main Loop """ ## subscribe this agent to all ## the messages of the switch mswitch.subscribe(self.iq) while True: envelope=self.iq.get(block=True) quit=mdispatch(self, self.id, envelope) if quit: shutdown_handler=getattr(self, "h_shutdown", None) if shutdown_handler is not None: shutdown_handler() break
def run(self): """ Main Loop """ self.dprint("Agent(%s) starting, debug(%s)" % (str(self.__class__), self._debug)) ## subscribe this agent to all ## the messages of the switch mswitch.subscribe(self.iq, self.isq) quit=False while not quit: #print str(self.__class__)+ "BEGIN" while True: try: envelope=self.isq.get(block=True, timeout=0.1) mquit=self._process(envelope) if mquit: quit=True break continue except KeyboardInterrupt: raise except Empty: break burst=self.LOW_PRIORITY_BURST_SIZE while True and not quit: try: envelope=self.iq.get(block=False)#(block=True, timeout=0.1) mquit=self._process(envelope) if mquit: quit=True break burst -= 1 if burst == 0: break except KeyboardInterrupt: raise except Empty: break self.dprint("Agent(%s) ending" % str(self.__class__))
def run(self): """ Main Loop """ print "Agent(%s) (%s) starting" % (self.agent_name, self.id) ## subscribe this agent to all ## the messages of the switch. ## Later on when the agent starts receiving messages, ## it will signal which 'message types' are of interest. mswitch.subscribe(self.id, self.iq, self.isq) quit=False while not quit: quit=process_queues(self, self.agent_name, self.id, self.mmap, self.responsesInterest, self.iq, self.isq, message_processor) print "Agent(%s) (%s) ending" % (self.agent_name, self.id)
def run(self): """ Main Loop """ ## subscribe this agent to all ## the messages of the switch mswitch.subscribe(self.iq, self.isq) quit=False while not quit: #print str(self.__class__)+ "BEGIN" while True: try: envelope=self.isq.get(block=True, timeout=0.1) mquit=self._process(envelope) if mquit: quit=True break continue except Empty: break burst=self.LOW_PRIORITY_BURST_SIZE while True and not quit: try: envelope=self.iq.get(block=False)#(block=True, timeout=0.1) mquit=self._process(envelope) if mquit: quit=True break burst -= 1 if burst == 0: break except Empty: break print str(self.__class__) + " - shutdown"
def __init__(self, debug=False): AgentBase.__init__(self, debug) mswitch.subscribe(self.id, self.iq, self.isq) print "Agent(%s) (%s) starting" % (self.agent_name, self.id)