import asyncio
async def count():
print("One")
await asyncio.sleep(1)
print("Two")
async def main():
await asyncio.gather(count(), count(), count())#多个任务
asyncio.run(main())#运行
加强理解异步.
输出:一一一,二二二,感觉类似这是个函数是多个函数在并行运行
.
import asyncio
async def count():
print("One")
await asyncio.sleep(1)
print("Two")
async def main():
await asyncio.gather(count(), count(), count())#多个任务
asyncio.run(main())#运行
加强理解异步.
输出:一一一,二二二,感觉类似这是个函数是多个函数在并行运行
.