文章詳情頁
python - asyncio.wait和asyncio.gather的區(qū)別?
瀏覽:105日期:2022-08-27 09:17:38
問題描述
剛學PYTHON的協(xié)程,我想請教下,這兩段代碼執(zhí)行起來有什么區(qū)別呢?
tasks = [asyncio.ensure_future(task(i)) for i in range(0,300)]loop.run_until_complete(asyncio.gather(*tasks))tasks = [task(i) for i in range(0,300)]loop.run_until_complete(asyncio.wait(tasks))
問題解答
回答1:看文檔就知道了,這兩段代碼的效果相同。但是 wait 和 gather 的返回值不一樣,wait 也可以在第一個 future 完全或者出錯時就返回。
回答2:RTFM......
相關文章:
排行榜
