python asyncio

bitterteaer / 2023-05-07 / 原文

例子

import asyncio
async def main():
  print("hello")
  await asyncio.sleep(1)
  print("world")

asyncio.run(main())

主要函数

task = asyncio.create_tas()
res = await asyncio.gather(task1, task2) # res: list

获取返回值

res = await task