apscheduler提示maximum错误
来源:互联网 发布:西安明朝万达 JAVA 编辑:程序博客网 时间:2024/06/05 01:50
起因
在tornado中用apscheduler实现计划任务,出现错误提示 “maximum number of running instances reached (1)”
2015-12-04 19:10:22,227 - apscheduler.scheduler - WARNING - Execution of job "TaskHandle.progress_job (trigger: date[2015-12-04 19:10:22 CST], next run at: 2015-12-04 19:10:22 CST)" skipped:
分析
缺乏资料,所以根据提示,分析apscheduler源码
- 记录异常位置
在源码目录下,搜索关键字maxinum,找到记录异常的位置
#apscheduler/schedulers/base.pyif run_times: try: executor.submit_job(job, run_times) except MaxInstancesReachedError: self._logger.warning( 'Execution of job "%s" skipped: maximum number of running instances reached (%d)', job, job.max_instances) except: self._logger.exception('Error submitting job "%s" to executor "%s"', job, job.executor)
- 异常抛出位置
继续看submit_job函数,找到异常抛出位置
#apscheduler/executors/base.pydef submit_job(self, job, run_times): """ Submits job for execution. :param Job job: job to execute :param list[datetime] run_times: list of datetimes specifying when the job should have been run :raises MaxInstancesReachedError: if the maximum number of allowed instances for this job has been reached """ assert self._lock is not None, 'This executor has not been started yet' with self._lock: if self._instances[job.id] >= job.max_instances: raise MaxInstancesReachedError(job) self._do_submit_job(job, run_times) self._instances[job.id] += 1
- _instances变量作用
在submit_job(提交任务)时加1,在_run_job_success(任务运行成功)时减1。 当self._instances[job.id]大于job.max_instances抛出异常。
max_instances默认值为1,它表示id相同的任务实例数。
解决
通过设置max_instances参数
sched.add_job(child_job, max_instances=10, trigger=DateTrigger(), id="123")
重现脚本
import timeimport tornado.ioloopfrom apscheduler.triggers.date import DateTriggerfrom apscheduler.schedulers.tornado import TornadoSchedulersched = TornadoScheduler()def child_job(): print "start" time.sleep(60) print "end"def main_job(): sched.add_job(child_job, trigger=DateTrigger(), id="123")sched.add_job(main_job, 'interval', seconds=5)sched.start()tornado.ioloop.IOLoop.instance().start()
- 输出
job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1job_id: 123, instances: 0, max_instances: 1startjob_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1job_id: 123, instances: 1, max_instances: 1WARNING:apscheduler.scheduler:Execution of job "child_job (trigger: date[2015-12-07 15:27:11 CST], next run at: 2015-12-07 15:27:11 CST)" skipped: maximum number of running instances reached (1)job_id: 7279209ab6c2498698f2117bb97e18a1, instances: 0, max_instances: 1
0 0
- apscheduler提示maximum错误
- APscheduler
- apscheduler
- 错误提示:Package Reference constraint name maximum length is limited to 30 character
- APScheduler应用
- apscheduler interval
- 错误提示
- 错误提示
- 错误提示
- 错误提示
- 错误提示
- 【python】python APScheduler 框架
- apscheduler定时任务
- APScheduler Multi CronTrigger 实现
- APScheduler基本使用
- Python的APScheduler模块
- Python 任务调度-APScheduler
- apscheduler 源码深度解析
- 将各种格式的图像转换为灰度图像
- leetcode:225 Implement Stack using Queues-每日编程第二十六题
- linux中报错:undefined reference to
- Mapreduce工作流程
- Spring scope属性详解
- apscheduler提示maximum错误
- DefaultHttpClient is deprecated
- hdu 2086 A1 = ?
- jenkins通过配置ansible传输文件,并且调度服务
- 决策树学习 之 概念与构造算法
- RFID扫描APP Android
- VMware Tools不能正常共享文件夹以及不支持USB3.0的解决方案
- Spring 3 MVC深入研究
- 如何用滚动视图实现新闻导航滚动条?