asyncio.Task.all_tasks()和asyncio.all_tasks()之间的区别是什么?
创始人
2024-09-21 05:30:52
0

asyncio.Task.all_tasks()是方法,只返回当前循环中所有挂起和运行的给定任务类型(默认为所有任务类型)。而asyncio.all_tasks()是一个协程函数,返回所有当前任务(挂起,正在运行,以及已完成的)的集合。

代码示例:

import asyncio

async def coro():
    await asyncio.sleep(1)

async def main():
    task = asyncio.create_task(coro())
    # run the coro
    await asyncio.sleep(0.5)
    all_tasks_1 = {t._coro for t in asyncio.Task.all_tasks()}
    print(f"all_tasks_1: {all_tasks_1}") 
    # print set() since the coro is running, not finished yet

    all_tasks_2 = await asyncio.all_tasks()
    print(f"all_tasks_2: {all_tasks_2}")
    # print ALL tasks, explicit base loop + implicit default loop
    # set() if there are no other running tasks besides main()

asyncio.run(main())

相关内容

热门资讯

透视安装!wepoker辅助器... 1、透视安装!wepoker辅助器是真的的吗,pokemomo辅助工具,2025版教程(本然真的是有...
透视存在!wpk辅助ai,德普... 透视存在!wpk辅助ai,德普之星透视免费,黑科技教程(总是真的有挂);建议优先通过wpk辅助ai透...
透视好友!wpk脚本是什么,德... 透视好友!wpk脚本是什么,德州透视脚本,规律教程(原生是真的有挂)是一款可以让一直输的玩家,快速成...
透视游戏!wepoker辅助器... 透视游戏!wepoker辅助器是真的的吗,hhpoker是真的假的,详细教程(原生是真的有挂),支持...
透视ai!wpk辅助工具,we... 1、透视ai!wpk辅助工具,wepoker免费脚本弱密码,存在挂教程(果然存在有挂)。2、wpk辅...
透视app!aapoker透视... 透视app!aapoker透视插件下载,wepoker网页版透视方法,安装教程(从来有挂)1、点击下...
透视ai!wpk脚本下载,we... 透视ai!wpk脚本下载,wepoker怎么发冤家牌,教你教程(一直是有挂);大神普及一款德州ai内...
透视科技!aapoker透视软... 透视科技!aapoker透视软件,hhpoker俱乐部是干嘛的,攻略方法(本来是真的有挂)是一款可以...
透视辅助!红龙poker有辅助... 透视辅助!红龙poker有辅助吗,wepoker网页版透视方法,安装教程(切实有挂);免费红龙pok...
透视app!wpk透视脚本视频... 透视app!wpk透视脚本视频,wejoker辅助器怎么卖,安装教程(素来是有挂);玩家在wpk透视...