开发者

apscheduler doesn't work normally

this is the code:

#coding=utf-8
from 开发者_如何学Capscheduler.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?


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 .


As mentioned in the documentation, if you want the Scheduler to block, you need to set the standalone flag to True.

s = Scheduler(standalone=True) 
<add jobs here>
s.start()

Make sure you add signal handlers or catch interrupt exceptions :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜