from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
def job_function():
print("Hello World")
sched = BlockingScheduler()
每2小时触发
sched.add_job(job_function, 'interval', hours=2)
sched.start()
设定执行区间
sched.add_job(job_function, 'interval', hours=2, start_date='2010-10-10 09:30:00', end_date='2014-06-15 11:00:00')
装饰器@sched.scheduled_job('interval',id='my_job_id',hours=2)
from apscheduler.scheduler import BlockingScheduler
@sched.scheduled_job('interval', id='my_job_id', hours=2)
def job_function():
print("Hello World")
每小时(上下浮动120秒区间内)运行job_function
sched.add_job(job_function, 'interval', hours=1, jitter=120)