def get_async_call_per_host(zk_client, args, call):
"""
:param args: arguments to pass into ``call``, this should be a list of znode paths for example.
:param call: a callable that accepts two arguments (KazooClient, arg)
where arg is an entry from args
``call`` should usually be a lambda such as::
lambda c, arg: c.get(arg)
returns a dictionary like::
{
arg_0: {
0: result or exception obj
1: result or exception obj
2: result or exception obj
},
arg_1: {
0: result or exception obj
1: result or exception obj
2: result or exception obj
},
}
"""
clients = kazoo_clients_from_client(zk_client)
kazoo_clients_connect(clients)
asyncs = defaultdict(dict)
for arg in args:
for client_idx, client in enumerate(clients):
asyncs[arg][client_idx] = call(client, arg)
# block until the calls complete
get_async_ready(asyncs)
results = defaultdict(dict)
for arg, host_async in six.viewitems(asyncs):
for host_idx, async_result in six.viewitems(host_async):
results[arg][host_idx] = async_result.exception or async_result.get()
return results
评论列表
文章目录