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
评论列表
文章目录