您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页apscheduler+threading多任务多线程调度

apscheduler+threading多任务多线程调度

来源:好走旅游网
import threading,logging,time
from apscheduler.schedulers.blocking import BlockingScheduler

def now_time():
	t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))

def job1():
	print('job1运行时间是:',time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
	time.sleep(10)

def job2():
	print('job2运行时间是:',time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
	time.sleep(20)
def job1_task():
	threading.Thread(target=job1).start()
def job2_task():
	threading.Thread(target=job2).start()

scheduler = BlockingScheduler()
# 在每天22点,每隔 1分钟 运行一次 job 方法
scheduler.add_job(job1_task, 'cron', minute='53,,58')
# 在每天22和23点的25分,运行一次 job 方法
scheduler.add_job(job2_task, 'cron', minute='53,51,55')

scheduler.start()
job2运行时间是: 2021-02-03 21:53:00
job1运行时间是: 2021-02-03 21:53:00
job1运行时间是: 2021-02-03 21::00
job2运行时间是: 2021-02-03 21:55:00
job1运行时间是: 2021-02-03 21:58:00

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务