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