python中普通函数调用协程
import asyncio
def target(loop, timeout=None):
future = asyncio.run_coroutine_threadsafe(add(1, b=2), loop)
return future.result(timeout)
async def add(a, b):
await asyncio.sleep(1)
return a + b
loop = asyncio.get_event_loop()
future = loop.run_in_executor(None, target, loop)
print(loop.run_until_complete(future))