今天看到一個比較人性化的定時模塊 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