现有需求是每隔10秒执行一次程序,不考虑执行程序的时间周期,固定时间间隔就执行一次
首先需要安装python3 schedule 模块
pip install schedule定时器代码
from threading import Thread import schedule def asynca(f): def wrapper(*args, **kwargs): thr = Thread(target=f, args=args, kwargs=kwargs) thr.start() return wrapper @asynca def do_ship(): tee.tu() tee.tt() #每隔10秒执行调用do_ship功能模块 schedule.every(10).seconds.do(do_ship) while True: schedule.run_pending()
示例引用代码
# 15秒执行一次 schedule.every(5).seconds.do(do_ship) # 15分钟执行一次 schedule.every(15).minutes.do(do_ship) # 3小时执行一次 schedule.every(3).hour.do(do_ship) # 限定时间执行 schedule.every().day.at("2:00").do(do_ship)
如需转载请保留本文出处: https://zhe94.com/935.html