APScheduler Cannot schedule new futures after shutdown

Viewed 2613

I am testing a use case when a scheduler is shutdown and started it has to pick all the schedules persisted in job store. I am facing the following issue when I am trying to start the schedule after shutting down. Below is the run time error.

RuntimeError: cannot schedule new futures after shutdown Error submitting job "testTrigger: interval[0:00:01], next run at: ... to executor default"

Code:

            from apscheduler.schedulers.background import BackgroundScheduler
            from apscheduler.jobstores.mongodb import MongoDBJobStore
            from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
            from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
            from apscheduler.schedulers.base import BaseScheduler
            
            jobstores = {
                'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')
            }
            
            executors = {
                'default': ThreadPoolExecutor(20),
                'processpool': ProcessPoolExecutor(5)
            }
            job_defaults = {
                'coalesce': False,
                'max_instances': 3
            }
            scheduler = BackgroundScheduler(jobstores=jobstores, executors=executors, 
            job_defaults=job_defaults, timezone=utc)
        
               def testTrigger(schedule):
                 print("APScheduler..."+str(schedule))
    
     scheduleList=[1,2]
        //Adding List of Jobs
    for schedule in scheduleList:
        scheduler.add_job(testTrigger,args=[schedule],'interval',seconds=schedule,id='schedule_'+str(schedule),replace_existing=true)
        
    if scheduler.running:
    else:
       scheduler.start
    #scheduler.shutdown()

Am I missing anything in understanding the behaviour

1 Answers

I called the start() method just once. When I called the shutdown(), then I just checked if this is first or not. It looks that shtudown() doesn't completely stop the task because if I insert the new job again, then those task performs well without calling the start() method.

Related