def run(self): """ The thread function. Intended for internal use by Node. Not intended to be part of the API. """ log.log("\n\nNode thread started") #TODO: (re-)enable creation of new transactions self.__stop = False while True: self.__network.processNetworkEvents(timeout=0.01) #API events: with self._commandFunctionLock: s = self._commandFunction if s != None: try: self._commandReturnValue = s[0](self, *s[1], **s[2]) except Exception as e: self._commandReturnValue = e log.logException() self._commandProcessed.set() self._commandFunction = None #Time-out events: while len(self.__node.timeoutMessages) > 0 and self.__node.timeoutMessages[0].timestamp < time.time(): msg = self.__node.timeoutMessages.pop(0) self.handleMessage(msg.message) #Connections: data transmission and closing doSaveState = False for localID, c in self.__node.connections.copy().iteritems(): #New attempt to send the outbox: if c.transmit(self.__network): doSaveState = True #Close interface whenever requested: if c.canBeClosed(): log.log('Closing persistent connection ' + localID) del self.__node.connections[localID] self.__network.closeInterface(localID) doSaveState = True if doSaveState: self.__node.save() if self.__stop: #TODO: stop creation of new transactions #TODO: only break once there are no more open transactions break log.log("Node thread terminated\n\n")
def run(self): """ The thread function. Intended for internal use by Node. Not intended to be part of the API. """ log.log("\n\nAmiko thread started") #Start listening listener = network.Listener(self.context, self.settings.listenHost, self.settings.listenPort) #TODO: (re-)enable creation of new transactions self.__stop = False while True: self.context.dispatchNetworkEvents() self.context.dispatchTimerEvents() self.watchdog.check() with self._commandFunctionLock: s = self._commandFunction if s != None: try: self._commandReturnValue = s[0](self, *s[1], **s[2]) except Exception as e: self._commandReturnValue = e log.logException() self._commandProcessed.set() self._commandFunction = None if self.__doSave: self.__saveState() self.__doSave = False self.__movePayeesToPayLog() if self.__stop: #TODO: stop creation of new transactions #TODO: only break once there are no more open transactions break #This closes all network connections etc. self.context.sendSignal(None, event.signals.quit) log.log("Node thread terminated\n\n")
def run(self): """ The thread function. Intended for internal use by Node. Not intended to be part of the API. """ log.log("\n\nNode thread started") self.__network.openListener() #Establish connections for ID in self.__node.connections.keys(): try: self.makeConnection(ID) except network.ConnectFailed as e: log.log("Connect failed (ignored)") #TODO: (re-)enable creation of new transactions self.__stop = False while True: self.__network.processNetworkEvents(timeout=0.01) #API events: with self._commandFunctionLock: s = self._commandFunction if s != None: try: self._commandReturnValue = s[0](self, *s[1], **s[2]) except Exception as e: self._commandReturnValue = e log.logException() self._commandProcessed.set() self._commandFunction = None #Time-out events: while len(self.__node.timeoutMessages) > 0 and self.__node.timeoutMessages[0].timestamp < time.time(): msg = self.__node.timeoutMessages.pop(0) self.handleMessage(msg.message) #Connections: data transmission and closing doSaveState = False for localID, c in self.__node.connections.copy().iteritems(): #New attempt to send the outbox: if c.transmit(self.__network): doSaveState = True #Close interface whenever requested: if c.canBeClosed(): log.log('Closing persistent connection ' + localID) del self.__node.connections[localID] self.__network.closeInterface(localID) doSaveState = True if doSaveState: self.__node.save() if self.__stop: #TODO: stop creation of new transactions #TODO: only break once there are no more open transactions break self.__network.closeAll() log.log("Node thread terminated\n\n")