阅读量:0
import time import asyncio async def down(url): print("你好,开始下载") await asyncio.sleep(3) print("你好,下载完成") async def main(): urls =[ 'www.baidu.com', 'www.google.com' 'www.163.com' ] masks=[] for url in urls: p= down(url) masks.append(p) done,pending=await asyncio.wait(masks) for task in done: print(f"{task}已完成下载") if __name__ == '__main__': t1=time.time() asyncio.run(main()) t2=time.time() print(t2-t1)