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))

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2021-10-11
  • 2021-11-22
  • 2021-04-16
  • 2021-10-30
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案