apscheduler 无法正常工作
这是代码:
#coding=utf-8
from apscheduler.scheduler import Scheduler
import logging
logging.basicConfig(filename='/tmp/log', level=logging.DEBUG,
format='%(levelname)s[%(asctime)s]: %(message)s')
sched = Scheduler()
sched.start()
#@sched.interval_schedule(seconds=3)
def job_function():
logging.debug('hello world')
sched.add_interval_job(job_function, seconds=3)
如果我切换到装饰器,仍然不起作用。日志是这样的:
DEBUG[2011-10-09 11:02:45,175]: Looking for jobs to run
DEBUG[2011-10-09 11:02:45,176]: No jobs; waiting until a job is added
INFO[2011-10-09 11:02:45,176]: Added job "job_function (trigger: interval[0:00:03], next run at: 2011-10-09 11:02:48.176444)" to job store "default"
INFO[2011-10-09 11:02:45,177]: Shutting down thread pool
添加了作业job_function
,但是神经触发了,为什么?
this is the code:
#coding=utf-8
from apscheduler.scheduler import Scheduler
import logging
logging.basicConfig(filename='/tmp/log', level=logging.DEBUG,
format='%(levelname)s[%(asctime)s]: %(message)s')
sched = Scheduler()
sched.start()
#@sched.interval_schedule(seconds=3)
def job_function():
logging.debug('hello world')
sched.add_interval_job(job_function, seconds=3)
if i switch to decorator, still doesn't work. the log is like this:
DEBUG[2011-10-09 11:02:45,175]: Looking for jobs to run
DEBUG[2011-10-09 11:02:45,176]: No jobs; waiting until a job is added
INFO[2011-10-09 11:02:45,176]: Added job "job_function (trigger: interval[0:00:03], next run at: 2011-10-09 11:02:48.176444)" to job store "default"
INFO[2011-10-09 11:02:45,177]: Shutting down thread pool
the job job_function
is added, but is nerver triggered, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这就是您的全部代码,那么它为什么不起作用就很清楚了——应用程序在计划执行作业之前退出。请参阅 https://bitbucket.org/agronholm/apscheduler/src/tip/ 中提供的示例示例。
If this is all your code, then it's clear why it's not working -- the application exits before the job is scheduled to be executed. See the examples provided at https://bitbucket.org/agronholm/apscheduler/src/tip/examples .
正如文档中所述,如果您想要调度程序要阻止,您需要将
standalone
标志设置为True
。确保添加信号处理程序或捕获中断异常:-)
As mentioned in the documentation, if you want the Scheduler to block, you need to set the
standalone
flag toTrue
.Make sure you add signal handlers or catch interrupt exceptions :-)