import apscheduler
import time
from apscheduler.schedulers.blocking import BlockingScheduler # 引入阻塞控制器
from apscheduler.schedulers.background import BackgroundScheduler # 引入后台控制器
from apscheduler.triggers.interval import IntervalTrigger # 引入间隔触发器
from apscheduler.triggers.date import DateTrigger # 引入日期触发器
from apscheduler.triggers.cron import CronTrigger
def my_job1():
print("myjob1")
def my_job2():
print("myjob2")
if __name__ == "__main__":
# scheduler = BackgroundScheduler() # 后台控制器
scheduler = BlockingScheduler() # 阻塞控制器
intervalTrigger = IntervalTrigger(seconds=5) # 间隔触发器
# intervalTrigger = DateTrigger(run_date="2022-01-26 16:21:00") # 日期触发器
# intervalTrigger = CronTrigger(second=5) # cron触发器
"""
每天的19:30:01执行作业
intervalTrigger = CronTrigger(hour=19, minute=30, second=1)
每年的10月1日19点执行作业
intervalTrigger = CronTrigger(month=10, day=1, hour=19)
"""
scheduler.add_job(my_job1, intervalTrigger, id="my_job1_id")
scheduler.add_job(my_job2, intervalTrigger, id="my_job2_id")
scheduler.start()
print("========end========")
apscheduler demo
最新推荐文章于 2024-11-02 16:28:26 发布