【问题标题】:APScheduler not executing the pythonAPScheduler 不执行 python
【发布时间】:2014-04-02 04:31:22
【问题描述】:

我正在学习 Python,并且正在修改高级调度程序。我无法让它工作。

import time
from datetime import datetime
from apscheduler.scheduler import Scheduler

sched = Scheduler(standalone=True)
sched.start()

#@sched.cron_schedule(second=5)
def s():
    print "hi"
sched.add_interval_job(s, seconds=10)
i=0
while True:
  print i
  i=i+1
  time.sleep(3)
sched.shutdown()

我确定我缺少一些基本的东西。有人能指出来吗?

您还会向高级调度程序推荐一个 crontab 吗?我希望我的脚本每 24 小时运行一次。 谢谢

【问题讨论】:

    标签: python crontab apscheduler


    【解决方案1】:

    独立模式意味着 sched.start() 会阻塞,所以它下面的代码不会被执行。所以先创建调度器,然后添加间隔作业,最后启动调度器。

    至于 crontab,那么 sched.add_cron_job(s, hour=0) 怎么样?这将在每天午夜执行。

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 2013-01-30
      相关资源
      最近更新 更多