我正在使用APScheduler运行一些定期任务,如下所示:
from apscheduler.scheduler import Scheduler
from time import time, sleep
apsched = Scheduler()
apsched.start()
def doSomethingRecurring():
pass # Do something really interesting here..
apsched.add_interval_job(doSomethingRecurring, seconds=2)
while True:
sleep(10)
因为间隔作业在脚本结束时结束,所以我只添加了结束while True
循环。我真的不知道这是不是最好的,更不用说Python式的方法了。有没有更好的方法?欢迎所有提示!在
尝试使用阻塞调度程序。apsched.开始()只会阻止。你必须在开始前设置好。在
编辑:回应评论的一些伪代码。在
试试这个代码。它将python脚本作为守护程序运行:
用法:
^{pr2}$相关问题 更多 >
编程相关推荐