def run(self): ''' Start the main loop of this node. ''' hex_id = get_hexid(self.node_id) try: while self.running: # Get new events from the I/O thread # while self.event_io.poll(0): if self.event_io.getsockopt(zmq.EVENTS) & zmq.POLLIN: msg = self.event_io.recv_multipart() route, eventname, data = msg[:-2], msg[-2], msg[-1] # route back to sender is acquired by reversing the incoming route route.reverse() if eventname == b'QUIT': print(f'# Node({hex_id}): Quitting (Received QUIT from server)') self.quit() else: pydata = msgpack.unpackb(data, object_hook=decode_ndarray, raw=False) self.event(eventname, pydata, route) # Perform a simulation step self.step() # Process timers Timer.update_timers() except KeyboardInterrupt: print(f'# Node({hex_id}): Quitting (KeyboardInterrupt)') self.quit()
def run(self): ''' Start the main loop of this node. ''' while self.running: # Perform a simulation step self.step() # Process timers Timer.update_timers()
def step(self): ''' Perform one iteration step. Reimplemented in Simulation. ''' # Process timers Timer.update_timers() # Get new events from the I/O thread # while self.event_io.poll(0): if self.event_io.getsockopt(zmq.EVENTS) & zmq.POLLIN: msg = self.event_io.recv_multipart() route, eventname, data = msg[:-2], msg[-2], msg[-1] # route back to sender is acquired by reversing the incoming route route.reverse() if eventname == b'QUIT': self.quit() else: pydata = msgpack.unpackb( data, object_hook=decode_ndarray, raw=False) bs.sim.event(eventname, pydata, route)
def step(self): ''' Perform one iteration step. Reimplemented in Simulation. ''' # Process timers Timer.update_timers() # Get new events from the I/O thread # while self.event_io.poll(0): if self.event_io.getsockopt(zmq.EVENTS) & zmq.POLLIN: msg = self.event_io.recv_multipart() route, eventname, data = msg[:-2], msg[-2], msg[-1] # route back to sender is acquired by reversing the incoming route route.reverse() if eventname == b'QUIT': self.quit() else: pydata = msgpack.unpackb( data, object_hook=decode_ndarray, encoding='utf-8') self.event(eventname, pydata, route)
def run(self): ''' Start the main loop of this node. ''' while self.running: # Get new events from the I/O thread while self.poll(): res = self.event_io.recv_multipart() sender_id = res[0] name = res[1] if name == b'QUIT': self.quit() else: data = msgpack.unpackb(res[2], object_hook=decode_ndarray, encoding='utf-8') self.event(name, data, sender_id) # Perform a simulation step self.step() # Process timers Timer.update_timers()
def run(self): ''' Start the main loop of this node. ''' while self.running: # Get new events from the I/O thread # while self.event_io.poll(0): if self.event_io.getsockopt(zmq.EVENTS) & zmq.POLLIN: msg = self.event_io.recv_multipart() route, eventname, data = msg[:-2], msg[-2], msg[-1] # route back to sender is acquired by reversing the incoming route route.reverse() if eventname == b'QUIT': self.quit() else: pydata = msgpack.unpackb(data, object_hook=decode_ndarray, encoding='utf-8') self.event(eventname, pydata, route) # Perform a simulation step self.step() # Process timers Timer.update_timers()
def step(self): ''' Perform one iteration step. Reimplemented in Simulation. ''' # Process timers Timer.update_timers()