def _call_handler(self, *, handler, args, kwargs, loop=None, start=True, executor=None):
if loop is None:
loop = asyncio.get_event_loop()
if (inspect.iscoroutinefunction(handler) or inspect.isgeneratorfunction(handler)):
# Get a coro/future
f = handler(*args, **kwargs)
else:
# run_in_executor doesn't support kwargs
handler = functools.partial(handler, *args, **kwargs)
# Get result/coro/future
f = loop.run_in_executor(executor, handler)
if start:
# Wrap future in a task, schedule it for execution
f = asyncio.ensure_future(f, loop=loop)
# Return a coro that awaits our existing future
return self._result_tuple(handler, f)
评论列表
文章目录