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)

 

输出结果:spa

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/ijdhPHeglenbSunxZl7GJAcode

 

终于能够用Python实现定时任务了!blog

 

谢谢utf-8

相关文章
相关标签/搜索