【问题标题】:Only run one job concurrently in apscheduler across the same scheduler仅在同一调度程序的 apscheduler 中同时运行一项作业
【发布时间】:2016-05-13 04:02:16
【问题描述】:

我试图确保在同一个调度程序中一次只运行一个作业。例如,我可能有这样的事情:

def echo_arg(arg):
  print 'Going to tell you the arg! The arg is: {0}'.format(arg)
  sleep(5)

def main():
  scheduler = BlockingScheduler()
  for i in range(0, 60):
      scheduler.add_job(echo_arg, 'cron', args=[i], second=i, max_instances=1)
  scheduler.start()

即使有 60 个不同的作业,我还是希望调度程序阻塞直到前一个作业完成。例如,0 秒处的作业应使 1、2、3 和 4 处的运行无效。有没有办法在调度程序本身中做到这一点?

谢谢!

【问题讨论】:

    标签: python cron daemon apscheduler


    【解决方案1】:

    是的,在只有 1 个工作线程的线程池执行器中运行它们。这样就不能同时运行任何作业。

    scheduler = BlockingScheduler(executors={'default': ThreadPoolExecutor(1)})
    

    如果作业有重叠的计划,请确保从默认值调整失火宽限时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2019-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多