import asyncio
import time
async def ceshi01(x,y):
await asyncio.sleep(y)
print(f"我是{x},我运行了{y}分钟")
async def yunxing():
group_a = asyncio.gather(ceshi01('A',5),ceshi01('a',3))
group_b = asyncio.gather(ceshi01('b',4),ceshi01('B',2))
await group_a
await group_b
print(asyncio.run(yunxing()))
和import asyncio
import time
async def ceshi01(x,y):
await asyncio.sleep(y)
print(f"我是{x},我运行了{y}分钟")
async def yunxing():
await asyncio.gather(ceshi01('A',5),ceshi01('a',3))
await asyncio.gather(ceshi01('b',4),ceshi01('B',2))
print(asyncio.run(yunxing()))
你觉得是是一样的吗 一样的你就完全没懂create_task做了什么 要是懂了你就可以自己写一个gather函数 哪怕不保序也可以 |