def __del__(self): try: self.debug("Destroy") self.deactivate() if self.mailbox: self.mailbox.unregister() self.destroy() except KeyboardInterrupt: self.error("Agent destruction interrupted!") self.send('application_interrupt') except FUSIL_ERRORS, error: writeError(self, error, "Agent destruction error")
def connect(self, address, family, type, timeout=5.0): try: self.info("Create socket (family %s, type %s)" % ( family, type)) self.socket = socket(family, type) self.socket.settimeout(timeout) self.info("Connect to %s" % formatAddress(family, address)) self.socket.connect(address) except socket_error, err: writeError(self, err, "Unable to connect to %s" % formatAddress(family, address)) self.socket = None self.send('application_error', 'Network connection failure')
def connect(self, address, family, type, timeout=5.0): try: self.info("Create socket (family %s, type %s)" % (family, type)) self.socket = socket(family, type) self.socket.settimeout(timeout) self.info("Connect to %s" % formatAddress(family, address)) self.socket.connect(address) except socket_error, err: writeError( self, err, "Unable to connect to %s" % formatAddress(family, address)) self.socket = None self.send('application_error', 'Network connection failure')
def main(self): try: if self.options.profiler: from fusil.profiler import runProfiler runProfiler(self, self.runProject, (self.options.project, )) else: self.runProject(self.options.project) except KeyboardInterrupt: self.error("Project interrupted!") self.exitcode = 1 except FUSIL_ERRORS, error: writeError(self, error) self.exitcode = 1
def bind(self, address, family=AF_INET, type=SOCK_STREAM, reuse_address=True): try: self.socket = socket(family, type) if reuse_address: self.socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) self.family = family self.socket.bind(address) self.socket.listen(self.backlog) self.error("Server waiting on %s" % formatAddress(family, address)) except socket_error, err: writeError(self, err, "Unable to bind on %s" % formatAddress(family, address)) self.socket = None self.send('application_error', 'Network server bind error')
def execute(self, project): try: age = 0 self.is_done = False while True: age += 1 self.debug("Univers step %s" % age) # Execute one univers step for agent in project.agents: self.executeAgent(agent) # Application is done? stop if self.is_done: return # Be nice with CPU: sleep some milliseconds sleep(self.step_sleep) except KeyboardInterrupt: self.error("Interrupt!") except FUSIL_ERRORS, error: writeError(self, error)