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