本文整理匯總了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