def make_concurrent_calls(*calls):
"""
If you need to make multiple concurrent calls, potentially to
different functions, or with different kwargs each time.
Args:
*calls (Iterable[Union[function, str], dict]) - list of
(func or func path, kwargs) tuples to call concurrently
Returns:
List[Any] - return values from each call in `calls`
(results are returned in same order as supplied)
"""
pool = Pool(len(calls))
results = []
for func, kwargs in calls:
results.append(
pool.apply_async(test_call, args=(func,), kwds=kwargs)
)
pool.close()
pool.join()
# add a bit of extra timeout to allow process terminate cleanup to run
# (because we also have an inner timeout on our ProcessManager thread join)
return [result.get(timeout=SUBPROCESS_TIMEOUT + 2) for result in results]
评论列表
文章目录