文章詳情頁
python - asyncio.wait和asyncio.gather的區別?
瀏覽:82日期:2022-08-27 09:17:38
問題描述
剛學PYTHON的協程,我想請教下,這兩段代碼執行起來有什么區別呢?
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......
相關文章:
1. macos - mac下docker如何設置代理2. java - 請問在main方法中寫成對象名.屬性()并賦值,與直接參參數賦值輸錯誤是什么原因?3. MySQL數據庫中文亂碼的原因4. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””5. docker不顯示端口映射呢?6. docker - 各位電腦上有多少個容器?。咳萜饕欢?,自己都搞混了,咋辦呢?7. android studio總是在processes running好久8. angular.js - 關于$apply()9. docker-compose 為何找不到配置文件?10. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下
排行榜
