如何在Flask中以高频率运行周期性任务?

2024-10-08 21:20:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望我的flask应用程序每隔200ms从本地txt文件中获取更新,有可能吗?在

另外,我考虑过apschedulerler中的BackgroundScheduler(),但是粒度是1s


Tags: 文件txt应用程序flask粒度backgroundschedulerapschedulerler
2条回答

你不能在下一次迭代之前在一个休眠200毫秒的线程中启动一个循环吗?在

不管你在函数里放了什么,每200毫秒就会处理一次

import datetime, threading

def foo():
    print datetime.datetime.now()
    threading.Timer(0.2, foo).start()

foo()

相关问题 更多 >

    热门问题