subscriber.py 文件源码

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

项目:jps 作者: OTL 项目源码 文件源码
def spin_once(self, polling_sec=0.010):
        '''Read the queued data and call the callback for them.
        You have to handle KeyboardInterrupt (\C-c) manually.

        Example:

        >>> def callback(msg):
        ...   print msg
        >>> sub = jps.Subscriber('topic_name', callback)
        >>> try:
        ...   while True:
        ...     sub.spin_once():
        ...     time.sleep(0.1)
        ... except KeyboardInterrupt:
        ...   pass

        '''
        # parse all data
        while True:
            socks = dict(self._poller.poll(polling_sec * 1000))
            if socks.get(self._socket) == zmq.POLLIN:
                msg = self._socket.recv()
                self._callback(msg)
            else:
                return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号