scheduler报错maximum number of running instances reached的原因和解决办法


先看一个demo来复现下这个错误:

from apscheduler.schedulers.blocking import BlockingScheduler
import time
from threading import Timer
from datetime import datetime

def test1(who):
    print("hello")
    print(datetime.now())

    time.sleep(20)
    print("this is %s" %who)
    print(datetime.now())


def scheduler_test():
    scheduler = BlockingScheduler()

    i=0
    while i<1:
        scheduler.add_job(test1, 'interval', seconds=10, id='test_job'+str(i), args=["xiao"+str(i)],next_run_time=datetime.now())
        i=i+1
        print("mmmmmmm")
    scheduler.start()

def timer1(who):
    who_tmp=who
    test1(who)
    Timer(20, timer_test,
          kwargs={'who': who_tmp}).start()

def timer_test():
    i=0
    while i<3:
        timer1("xiao"+str(i))


if __name__ == '__main__':
    #timer_test()
    scheduler_test()
    print("when")

 

 可以看到interval时长小于job的执行时长时,会触发这个错误maximum number of running instances reached

解决办法有两个,1、修改add_job接口的interval时长,使之大于job的执行时长  2、add_job接口加个参数,比如 max_instances=20,调大允许的并发个数

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM