helpers.py 文件源码

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

项目:django-concurrent-test-helper 作者: depop 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号