apscheduler 无法正常工作

发布于 2024-12-08 14:56:29 字数 850 浏览 4 评论 0原文

这是代码:

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终 2024-12-15 14:56:29

如果这就是您的全部代码,那么它为什么不起作用就很清楚了——应用程序在计划执行作业之前退出。请参阅 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 .

空心↖ 2024-12-15 14:56:29

正如文档中所述,如果您想要调度程序要阻止,您需要将 standalone 标志设置为 True

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

确保添加信号处理程序或捕获中断异常:-)

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 :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文