本文整理汇总了Python中zmq.green.green方法的典型用法代码示例。如果您正苦于以下问题:Python green.green方法的具体用法?Python green.green怎么用?Python green.green使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq.green
的用法示例。
在下文中一共展示了green.green方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_rpc
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import green [as 别名]
def send_rpc(self, dest, method, params,
block=True, timeout=None):
if self.context is None:
LOG.error('send_rpc to {} when not connected'.format(dest))
return
id_ = str(uuid.uuid1())
body = {
'method': method,
'id': id_,
'params': params
}
socket = self.context.socket(zmq.REQ)
if dest[0] == '@':
address = 'ipc://@/var/run/minemeld/{}:rpc'.format(
dest[1:]
)
else:
address = 'ipc:///var/run/minemeld/{}:rpc'.format(
dest
)
socket.connect(address)
socket.setsockopt(zmq.LINGER, 0)
socket.send_json(body)
LOG.debug('RPC sent to {}:rpc for method {}'.format(dest, method))
if not block:
socket.close(linger=0)
return
if timeout is not None:
# zmq green does not support RCVTIMEO
if socket.poll(flags=zmq.POLLIN, timeout=int(timeout*1000)) != 0:
result = socket.recv_json(flags=zmq.NOBLOCK)
else:
socket.close(linger=0)
raise RuntimeError('Timeout in RPC')
else:
result = socket.recv_json()
socket.close(linger=0)
return result