如何每隔x秒运行一次python脚本

时间:2017-03-25 03:51:37

标签: python multithreading

我已经尝试了schedule库但是我的代码有时停止,这也意味着调度代码停止。

import schedule
import time
import app

schedule.every(3).seconds.do(app.run)
while 1:
    try:
        schedule.run_pending()
    except Exception as e:
        print e
        pass

app.run是脚本,它使用队列和线程来请求交换数据。其中一个交换机随机抛出一个错误,因为线程(我认为)代码进入了一个不稳定的状态。我似乎无法解决这个问题,但是问题的一个肮脏修复就是每x次强制运行一次脚本(在我的情况下我需要10秒)任何想法?

1 个答案:

答案 0 :(得分:1)

除了显而易见的方式(包含while True:包含action()sleep(10)的帖子),您可以使用threading.Timersched module

相关问题