asyncio和trio在小睡眠时间上的anyio.sleep()时间不一致性。
创始人
2024-09-21 06:30:26
0

使用三元组库的time模块中的sleep()代替anyio.sleep()。

示例代码:

import time
import trio
import asyncio
import anyio

async def asyncio_sleep():
    start = asyncio.get_running_loop().time()
    await asyncio.sleep(0.001)
    elapsed = asyncio.get_running_loop().time() - start
    print(f"asyncio: {elapsed:.5f} seconds")

async def trio_sleep():
    start = time.monotonic()
    await trio.sleep(0.001)
    elapsed = time.monotonic() - start
    print(f"trio: {elapsed:.5f} seconds")

async def anyio_sleep():
    start = anyio.get_running_loop().time()
    await anyio.sleep(0.001)
    elapsed = anyio.get_running_loop().time() - start
    print(f"anyio: {elapsed:.5f} seconds")

async def main():
    await asyncio.gather(asyncio_sleep(), trio_sleep(), anyio_sleep())

asyncio.run(main())

使用time.monotonic()代替anyio.get_running_loop().time()可以解决该问题。在小睡眠时间上使用上述代码可以得到准确的结果。

相关内容

热门资讯

透视讲解!wpk私人局有透视吗... 您好,wepoker透视辅助下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
透视app!红龙poker有辅... 透视app!红龙poker有辅助吗(透视)开挂辅助器(果然存在有挂)-哔哩哔哩所有人都在同一条线上,...
透视辅助!epoker透视底牌... 透视辅助!epoker透视底牌,哈糖大菠萝开挂,阶段教程(总是是有挂)-哔哩哔哩1、玩家可以在哈糖大...
透视插件!wepoker辅助器... 透视插件!wepoker辅助器激活码(透视)开挂辅助器(其实有挂)-哔哩哔哩1)wepoker辅助器...
透视教程!hhpoker德州挂... 透视教程!hhpoker德州挂真的有吗,werplan透视挂,学习教程(一贯存在有挂)-哔哩哔哩1、...
透视游戏!aapoker免费透... 透视游戏!aapoker免费透视脚本,xpoker辅助工具,诀窍教程(一贯存在有挂)-哔哩哔哩1)a...
透视大厅!aa poker透视... 透视大厅!aa poker透视软件(透视)开挂辅助器(原来是有挂)-哔哩哔哩1、超多福利:超高返利,...
透视脚本!xpoker辅助工具... 透视脚本!xpoker辅助工具,pokernow辅助工具,方案教程(一贯真的有挂)-哔哩哔哩1、不需...
透视修改器!wepoker透视... 透视修改器!wepoker透视有吗(透视)开挂辅助神器(竟然是有挂)-哔哩哔哩wepoker透视有吗...
透视科技!wejoker透视方... 透视科技!wejoker透视方法,wepoker线上大神,操作教程(确实存在有挂)-哔哩哔哩在进入w...