使用APScheduler实现定时任务

安装开发库

# pip install apscheduler

from apscheduler.schedulers.blocking import BlockingScheduler

用法

# job_func是要被执行的函数

sched = BlockingScheduler()
sched.add_job(job_func, 'interval', minutes=2)
sched.start()

cron表达式的例子

# 时间: 周一到周五每天早上9点15, 执行job_func
sched.add_job(job_func, 'cron', day_of_week='mon-fri', hour=9, minute=15)

# 每隔两分钟调用一次
sched.add_job(job_func, 'interval', minutes=2)

工具

https://www.bejson.com/othertools/cron/


版权声明:本文为turui原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。