今天看到一个比较人性化的定时模块 schedule,目前 star 数为 6432,仍是很是的受欢迎,这个模块也是秉承这 For Humans 的原则,这里推荐给你们。地址 https://github.com/dbader/schedulegit
1.经过 pip 便可安装。github
pip install schedule
2.使用案例函数
import schedule import time def job(): print("I'm working...") schedule.every(10).minutes.do(job) schedule.every().hour.do(job) schedule.every().day.at("10:30").do(job) schedule.every().monday.do(job) schedule.every().wednesday.at("13:15").do(job) schedule.every().minute.at(":17").do(job) while True: schedule.run_pending() time.sleep(1)
从单词的字面意思,你就知道这是作什么的。
举个例子:
schedule.every().monday.do(job)
这句代码做用就是就是单词意思,定时器会每一个周一运行函数 job,怎么样是否是很简单。spa