示例#1
0
文件: node.py 项目: zeyefkey/bluesky
    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()
示例#2
0
    def run(self):
        ''' Start the main loop of this node. '''
        while self.running:
            # Perform a simulation step
            self.step()

            # Process timers
            Timer.update_timers()
示例#3
0
    def run(self):
        ''' Start the main loop of this node. '''
        while self.running:
            # Perform a simulation step
            self.step()

            # Process timers
            Timer.update_timers()
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
    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()
示例#7
0
    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()
示例#8
0
    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()
示例#9
0
    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()
示例#10
0
 def step(self):
     ''' Perform one iteration step. Reimplemented in Simulation. '''
     # Process timers
     Timer.update_timers()