core.py 文件源码

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

项目:agentzero 作者: gabrielfalcao 项目源码 文件源码
def set_topic(self, name, topic):
        """shortcut to :py:meth:SocketManager.set_socket_option(zmq.TOPIC, topic)

        :param name: the name of the socket where data will pad through
        :param topic: the option from the ``zmq`` module

        **Example:**

        ::

          >>> import zmq
          >>> from agentzero.core import SocketManager
          >>>
          >>> sockets = SocketManager()
          >>> sockets.ensure_and_bind('events', zmq.SUB, 'tcp://*:6000', zmq.POLLIN)
          >>>
          >>> # subscribe only to topics beginning with "logs"
          >>> sockets.set_topic('events', 'logs')
          >>> event = sockets.recv_event_safe('events')
          >>> event.topic, event.data
          'logs:2016-06-20', {'stdout': 'hello world'}
        """

        safe_topic = bytes(topic)
        self.set_socket_option(name, self.zmq.SUBSCRIBE, safe_topic)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号