本文整理汇总了Python中zmq.green方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.green方法的具体用法?Python zmq.green怎么用?Python zmq.green使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.green方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_green_device
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import green [as 别名]
def test_green_device(self):
rep = self.context.socket(zmq.REP)
req = self.context.socket(zmq.REQ)
self.sockets.extend([req, rep])
port = rep.bind_to_random_port('tcp://127.0.0.1')
g = gevent.spawn(zmq.green.device, zmq.QUEUE, rep, rep)
req.connect('tcp://127.0.0.1:%i' % port)
req.send(b'hi')
timeout = gevent.Timeout(3)
timeout.start()
receiver = gevent.spawn(req.recv)
self.assertEqual(receiver.get(2), b'hi')
timeout.cancel()
g.kill(block=True)
示例2: create
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import green [as 别名]
def create(cls, zmq_context, endpoint):
"""Create new server transport.
Instead of creating the socket yourself, you can call this function and
merely pass the :py:class:`zmq.core.context.Context` instance.
By passing a context imported from :py:mod:`zmq.green`, you can use
green (gevent) 0mq sockets as well.
:param zmq_context: A 0mq context.
:param endpoint: The endpoint clients will connect to.
"""
socket = zmq_context.socket(zmq.ROUTER)
socket.bind(endpoint)
return cls(socket)