trex_stl_async_client.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:trex-http-proxy 作者: alwye 项目源码 文件源码
def _run (self):

        # socket must be created on the same thread 
        self.socket.setsockopt(zmq.SUBSCRIBE, b'')
        self.socket.setsockopt(zmq.RCVTIMEO, 5000)
        self.socket.connect(self.tr)

        got_data = False

        self.monitor.reset()


        while self.active:
            try:

                with self.monitor:
                    line = self.socket.recv_string()

                self.monitor.on_recv_msg(line)

                self.last_data_recv_ts = time.time()

                # signal once
                if not got_data:
                    self.event_handler.on_async_alive()
                    got_data = True


            # got a timeout - mark as not alive and retry
            except zmq.Again:
                # signal once
                if got_data:
                    self.event_handler.on_async_dead()
                    got_data = False

                continue

            except zmq.ContextTerminated:
                # outside thread signaled us to exit
                assert(not self.active)
                break

            msg = json.loads(line)

            name = msg['name']
            data = msg['data']
            type = msg['type']
            baseline = msg.get('baseline', False)

            self.raw_snapshot[name] = data

            self.__dispatch(name, type, data, baseline)


        # closing of socket must be from the same thread
        self.socket.close(linger = 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号