python定时任务调度——apscheduler模块
来源:互联网 发布:钟表行业数据 编辑:程序博客网 时间:2024/06/05 09:48
一、基本概念
APScheduler
(Advanced Python Scheduler),基于Quartz的轻量级Python定时任务调度框架
1.1 四个主要组件:
trigger
、jobstores
、executors
、scheduler
executor
任务执行器:执行任务的模块,不同的IO模型选择相适应的executorjobstore
任务存储仓库:持久存储任务trigger
任务触发器:定义任务按何种条件触发scheduler
任务控制器:通过配置executor、jobstore、trigger,使用线程池(ThreadPoolExecutor默认值20)或进程池(ProcessPoolExecutor 默认值5)并且默认最多3个(max_instances)任务实例同时运行,实现对job的增删改查等调度控制
1.2 七种 scheduler
BlockingScheduler、BackgroundScheduler、AsyncIOScheduler、GeventScheduler、TornadoScheduler、TwistedScheduler、QtScheduler
1.3 四种 jobstore
MemoryJobStore、sqlalchemy、MongoDB、Redis
1.4 三种 trigger
date
:固定日期触发器:任务只运行一次,运行完毕自动清除;若错过指定运行时间,任务不会被创建interval
: 时间间隔触发器cron
: cron风格的任务触发
二、简单使用方式
2.1 内存存储job
注:命令行输入python apscheduler_test.py
启动程序;按CTRL+Break
安全退出程序,但任务不会被清除;按CTRL+C
退出程序,同时任务会被清除;可根据需要,选择以何种方式退出程序
2.2 sqlalchemy 存储job
注:命令行输入python apscheduler_test.py
启动程序后,会在当前工作目录生成jobs.sqlite数据库文件;sqlalchemy默认使用SQLite
存储job,table名默认为apscheduler_jobs
;用SQLite Database Browser打开该文件,各任务显示如下:
2.3 mongodb 存储job
注:运行程序前,确保已开启本机mongodb服务;命令行输入python apscheduler_test.py
启动程序;
2.4 事件监听器
注:命令行输入python apscheduler_test.py
启动程序后,得到如下反馈:
2.5 BackgroundScheduler
参考
[1] https://bitbucket.org/agronholm/apscheduler/src
[2] http://apscheduler.readthedocs.org/en/latest/userguide.html#code-examples
[3] http://www.bubuko.com/infodetail-716148.html
- python定时任务调度——apscheduler模块
- python定时任务调度——apscheduler模块
- Python定时任务调度——APScheduler
- 【python】Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python任务调度模块 – APScheduler
- Python 任务调度-APScheduler
- python定时任务调度库apscheduler的使用
- Python APScheduler任务调度器
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- struts2验证码及错误解决
- Java 对文件夹的常用操作
- CSS盒模型
- JavaWeb中Servlet技术之监听器
- Robot Framework安装及执行用例过程中遇到的问题及解决方法
- python定时任务调度——apscheduler模块
- 你不知道的JS——札记(二)
- 程序员_你和高考隔了几年?
- cocopods管理framework
- 玩转Google开源C++单元测试框架Google Test系列(gtest)之二
- CABasicAnimation学习Demo 包括了一些常用的动画效果
- V5 三目运算符解决Infinity问题
- struts2与json
- Java_log2000_类与对象5