【问题标题】:python apscheduler - skipped: maximum number of running instances reachedpython apscheduler - 跳过:达到最大运行实例数
【发布时间】:2016-03-05 08:40:29
【问题描述】:

我正在使用 Python apscheduler(版本 3.0.1)每秒执行一个函数

代码

scheduler = BackgroundScheduler()
scheduler.add_job(runsync, 'interval', seconds=1)
scheduler.start()

它大部分时间都运行良好,但有时我会收到以下警告:

WARNING:apscheduler.scheduler:Execution of job "runsync (trigger: interval[0:00:01], next run at: 2015-12-01 11:50:42 UTC)" skipped: maximum number of running instances reached (1)

1.这是执行此方法的正确方法吗?

2.这个警告是什么意思?它是否会影响函数内部任务的执行?

3.如何处理?

【问题讨论】:

    标签: python cron scheduler apscheduler


    【解决方案1】:

    增加max_instances

    如果特定用例允许,只需增加max_instances,如下所示。

    import apscheduler.schedulers.background
    
    scheduler = apscheduler.schedulers.background.BackgroundScheduler({'apscheduler.job_defaults.max_instances': 2})
    

    apscheduler 共有三种配置样式。这些在documentation 中有描述。上面是字典/JSON样式,下面是参数样式:

    import apscheduler.schedulers.background
    
    scheduler = apscheduler.schedulers.background.BackgroundScheduler(job_defaults={'max_instances': 2})
    

    【讨论】:

      【解决方案2】:

      我很确定我的任务不会超过时间间隔。我只是跟着这个answer 而不是按照here 的建议切换到apscheduler==2.1.2

      【讨论】:

        【解决方案3】:

        如果您希望同时运行同一作业的实例并避免警告,您可以在调度程序的add_job() 方法中包含max_instances 参数。默认值为一。

        【讨论】:

          【解决方案4】:

          这意味着任务花费的时间超过一秒,默认情况下,给定作业只允许一次并发执行。在不知道任务是什么的情况下,我无法告诉您如何处理。

          【讨论】:

          • 嗨,Alex,任务检查 FTP 位置内的文件夹,如果找到该文件夹​​,它会开始从这些文件夹中获取数据,这可能需要长达 24 小时。
          • 由于这个过程需要一秒钟以上的时间,你会经常看到这些警告。不过你不需要做任何事情。
          猜你喜欢
          • 2017-10-04
          • 1970-01-01
          • 1970-01-01
          • 2020-12-07
          • 1970-01-01
          • 1970-01-01
          • 2021-12-10
          • 2021-03-01
          • 1970-01-01
          相关资源
          最近更新 更多