Repeating job with very short interval triggers exception on shutdown: 'RuntimeError: cannot schedule new futures after shutdown'
See original GitHub issueThis code hits the problem pretty reliably (~75% of the time on python2, only ~60% of the time on python3 for some reason):
from apscheduler.schedulers.background import BackgroundScheduler
import time
import logging
logging.basicConfig()
def dummy_job():
print("test")
scheduler = BackgroundScheduler()
executors = {
'default': {
'type': 'threadpool',
'max_workers': 20
}
}
scheduler.configure(executors=executors)
scheduler.start()
scheduler.add_job(func=dummy_job, trigger='interval', seconds=0.05)
time.sleep(0.5)
scheduler.shutdown()
This code gives the following output when run:
test
test
test
test
test
test
test
test
test
ERROR:apscheduler.scheduler:Error submitting job "dummy_job (trigger: interval[0:00:00.050000], next run at: 2018-02-03 12:40:57 GMT)" to executor "default"
Traceback (most recent call last):
File "/data/build/ext/apscheduler/apscheduler/schedulers/base.py", line 960, in _process_jobs
executor.submit_job(job, run_times)
File "/data/build/ext/apscheduler/apscheduler/executors/base.py", line 71, in submit_job
self._do_submit_job(job, run_times)
File "/data/build/ext/apscheduler/apscheduler/executors/pool.py", line 22, in _do_submit_job
f = self._pool.submit(run_job, job, job._jobstore_alias, run_times, self._logger.name)
File "/usr/lib64/python3.3/concurrent/futures/thread.py", line 97, in submit
raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown
This is a regression introduced by #268 - reverting that fix causes it to cease hitting this problem at all.
The reason we are hitting this is that we have a repeating job running with a 100ms interval whenever the scheduler is running. Since upgrading to v3.5.1 we hit this error every time the scheduler is stopped.
I’m not sure what the right fix is - obviously you can’t just revert #268. Maybe BaseScheduler._process_jobs
could check whether the scheduler is running before it does anything else?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:22 (8 by maintainers)
Top Results From Across the Web
RuntimeError: cannot schedule new futures after shutdown
Repeating job with very short interval triggers exception on shutdown: 'RuntimeError: cannot schedule new futures after shutdown'
Read more >cannot schedule new futures after interpreter shutdown - Stack ...
I reported a bug here, and got this solution as a reply, which fixed it for me. I had the very same error...
Read more >RuntimeError: Cannot schedule new tasks after shutdown
The point of the test is to make sure that if the scheduler has to be shut down, it can recover: When it...
Read more >APScheduler 3.9.1.post1 - PythonFix.com
The project is very popular with an impressive 4689 github stars! ... shutdown: 'RuntimeError: cannot schedule new futures after shutdown'.
Read more >APScheduler Documentation - Read the Docs
When you schedule a job, you need to choose a trigger for it. The trigger determines the ... coalescing turned off for new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve fixed this in the 3.x branch now (at least I can’t repro anymore). Release is imminent, but feel free to test already.
Is there any update on this issue? I’ve recently encountered this on python 3.9