小编une*_*ven的帖子

asyncio 以不同的时间间隔定期运行两个不同的函数

是否可以使用 asyncio 为每个函数以不同的间隔定期运行 2 个不同的函数f

如果是 - 您能否提供代码示例。

import asyncio

async def f1(host,*arg):
    # call every 1 sec
    pass

async def f2(url,*args):
    # call every 2 sec
    pass
Run Code Online (Sandbox Code Playgroud)

预期输出:

00:00 f1 for 1.1.1.1

00:01 f1 for 1.1.1.1

00:02 f2 for 'google.com'

00:02 f1 for 1.1.1.1

00:03 f1 for 1.1.1.1

00:04 f2 for 'google.com'
Run Code Online (Sandbox Code Playgroud)

python-3.x python-asyncio

2
推荐指数
1
解决办法
1330
查看次数

标签 统计

python-3.x ×1

python-asyncio ×1