api.py 文件源码

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

项目:pscheduler 作者: perfsonar 项目源码 文件源码
def api_has_services(hosts, timeout=5, bind=None, threads=10):
    """
    Do a parallel rendition of the two functions above.

    Returns a hash of host names and results
    """

    # Work around a bug in 2.6
    # TODO: Get rid of this when 2.6 is no longer in the picture.
    if not hasattr(threading.current_thread(), "_children"):
        threading.current_thread()._children = weakref.WeakKeyDictionary()

    pool = multiprocessing.dummy.Pool(processes=min(len(hosts), threads))

    def check_one(arg):
        host, service, function = arg
        return (host, service, function(host, timeout=timeout, bind=bind))

    args = []
    result = {}
    for host in hosts:
        args.extend([
            (host, "bwctl", api_has_bwctl),
            (host, "pscheduler", api_has_pscheduler)
            ])
        result[host] = {
            "bwctl": None,
            "pscheduler": None
        }


    for host, service, state in pool.imap(check_one, args, chunksize=1):
        result[host][service] = state
    pool.close()
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号