Python定时任务APScheduler框架的使用
来源:互联网 发布:手机如何切换软件 编辑:程序博客网 时间:2024/06/04 18:07
Python定时任务APScheduler框架的使用
测试使用APScheduler框架的后台调度器运行写文件job不生效,但是Blocking调度器可正常工作,不知道怎么回事了。。。
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2017/11/26 下午9:42# @Author : 冷月孤心# @Mail : codenutter@foxmail.com# @File : apscheduler_demo.pyfrom apscheduler.schedulers.blocking import BlockingSchedulerfrom apscheduler.schedulers.background import BackgroundSchedulerfrom datetime import datetimeimport loggingdef init_logger(filename, level, format, datefmt): """ 初始化日志记录器 :param filename: 日志文件名 :param level: 日志级别 :param format: 格式化输出 :param datefmt: 日志日期格式 :return: None """ logging.basicConfig(filename=filename, level=level, format=format, datefmt=datefmt)init_logger('apsched.log', logging.DEBUG, '%(asctime)s|%(levelname)s|%(message)s', '%Y-%m-%d %H:%M:%S')def job1(): print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))def job2(): with open('hello.txt', 'a') as f: f.write("hello, world!\n")"""BlockingScheduler 是 APScheduler 中的调度器,APScheduler 中有两种常用的调度器BlockingScheduler 和 BackgroundScheduler,当调度器是应用中唯一要运行的任务时,使用 BlockingSchedule,如果希望调度器在后台执行,使用 BackgroundScheduler。"""# 定义调度器类型:BlockingScheduler 前台阻塞调度器#sched = BlockingScheduler()sched = BackgroundScheduler()sched.add_job(job1, 'interval', seconds=5, max_instances=10)sched.add_job(job2, 'interval', seconds=1, max_instances=10)sched.start()sched.shutdown()
阅读全文
0 0
- Python定时任务APScheduler框架的使用
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- Python定时任务框架APScheduler
- python定时任务运行框架APScheduler解析
- python定时任务调度库apscheduler的使用
- Python定时任务框架APScheduler 3.0.3 Cron示例
- 强大的python 定时任务框架 APScheduler 类似java的Quartz
- Python学习笔记 - 使用APScheduler管理定时任务
- 分布式定时任务框架——python定时任务框架APScheduler扩展
- 分布式定时任务框架——python定时任务框架APScheduler扩展
- APScheduler 基于Quartz的一个定时任务框架
- Flask结合APScheduler实现定时任务框架
- Python定时任务调度——APScheduler
- APScheduler执行定时任务---简单使用
- apscheduler定时任务
- python定时任务调度——apscheduler模块
- Java任务--Map
- python 字典
- 内存操作函数memcpy、memmove
- Grunt 笔记
- 习题6.16
- Python定时任务APScheduler框架的使用
- os.path
- Python 元组
- js中通过split函数分割字符串成数组
- FZU
- 集装箱数据众包平台中期检查个人总结
- R和RStudio软件安装
- 大数据处理框架的类型、比较和选择
- LeetCode.215 Kth Largest Element in an Array