美文网首页
2020-08-21 apscheduler 任务调度库

2020-08-21 apscheduler 任务调度库

作者: 喵呜e喵星人 | 来源:发表于2020-08-21 23:33 被阅读0次

触发器:
1.data 特定的时间点触发,只执行一次。
2.interval 固定时间间隔触发。
3.corn 在特定时间周期性地触发。
eg:

import  time,os
from apscheduler.schedulers.blocking import BlockingScheduler

def job1(arg,arg2):
    print("do job 1",arg,arg2,time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
    time.sleep(2)

def job2():
    print('do job 2',time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
    time.sleep(4)

def job3():
    print('do job 3',time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
    time.sleep(4)

if __name__=='__main__':
    print("begin....")
    scheduler = BlockingScheduler()
    scheduler.add_job(job3,'cron',hour=23,minute=6)  #每天23点6分执行
    scheduler.add_job(job1,'interval',seconds=3,args=['hello','你好']) #每隔3秒执行
    scheduler.add_job(job2,'cron',hour='20-23',minute='30-59',second='*/5') #每天20点到23点的,30分到59分,每隔5秒执行
    scheduler.add_job(os.system,'interval',seconds=5,args=['dir /b'])  #每隔5秒执行
    scheduler.start()

参考1
参考2
参考3

相关文章

网友评论

      本文标题:2020-08-21 apscheduler 任务调度库

      本文链接:https://www.haomeiwen.com/subject/uqkmjktx.html