Python之schedule用法,类似linux下的crontab

# -*- coding: utf-8 -*-
# author:baoshan


import schedule
import time

def job():
    print("I'm working...", str(time.strftime("%x %X", time.localtime())))

schedule.every(2).seconds.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("15:44").do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("15:45").do(job)
schedule.every().minute.at(":17").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

输出结果:

I'm working... 08/19/19 15:44:39
I'm working... 08/19/19 15:44:41
I'm working... 08/19/19 15:44:43
I'm working... 08/19/19 15:44:45
I'm working... 08/19/19 15:44:47
I'm working... 08/19/19 15:44:49
I'm working... 08/19/19 15:44:51

参考自:https://mp.weixin.qq.com/s/ijdhPHeglenbSunxZl7GJA

终于可以用Python实现定时任务了!

谢谢

原文地址:https://www.cnblogs.com/zhzhang/p/11377577.html