python 基于APScheduler的定时任务
指定时间执行指定任务:
1 # --*-- coding: utf--8 --*-- 2 # __author__ = 'xxx' 3 4 from datetime import datetime 5 from apscheduler.schedulers.blocking import BlockingScheduler 6 from a import a1 7 from b import b1 8 from c import c1 9 10 print(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) 11 12 13 def func(exec_type): 14 scheduler = BlockingScheduler() 15 exec_time = "2023-02-17 05:00:00" 16 if exec_type == "a": 17 scheduler.add_job(a1, 'date', run_date=exec_time, args=[100]) #添加参数 18 elif exec_type == "b": 19 scheduler.add_job(b1, 'date', run_date=exec_time) 20 elif exec_type == "c": 21 scheduler.add_job(c1, 'date', run_date=exec_time, args=[10, 100, "pic"]) 22 scheduler.start() 23 24 25 func(exec_type="a")
参考链接:https://blog.csdn.net/weixin_44799217/article/details/127353134