healthy.py 文件源码

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

项目:solr-zkutil 作者: bendemott 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号