threads.py 文件源码

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

项目:asyncio_extras 作者: agronholm 项目源码 文件源码
def call_in_executor(func: Callable, *args, executor: Executor = None, **kwargs) -> Future:
    """
    Call the given callable in an executor.

    This is a nicer version of the following::

        get_event_loop().run_in_executor(executor, func, *args)

    If you need to pass keyword arguments named ``func`` or ``executor`` to the callable, use
    :func:`functools.partial` for that.

    :param func: a function
    :param args: positional arguments to call with
    :param executor: the executor to call the function in
    :param kwargs: keyword arguments to call with
    :return: a future that will resolve to the function call's return value

    """
    callback = partial(func, *args, **kwargs)
    return get_event_loop().run_in_executor(executor, callback)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号