-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: cannot schedule new futures after interpreter shutdown #985
Comments
I’m encountering the same issue with APScheduler
Is there a workaround or fix available? I’d appreciate any guidance or suggestions. |
How are you reproducing this issue? The code OP posted is wrong, as it uses a |
@BRGustavo I cannot reproduce the problem with your script. Once I fixed the obvious bugs (the logging pointing to a nonexistent path and the @fti-rgurav please provide further information. Unless I get proof that there is an actual bug, I will close the issue. I won't spend a lot of time on a wild goose chase. |
There seems to be a Race Condition, a small window of time between when the scheduler is shut down and when the job submission is attempted, leading to this error. I am using I got it to reproduce using the following code. Started the script, and import atexit
from apscheduler.executors.pool import ThreadPoolExecutor
from apscheduler.schedulers.background import BackgroundScheduler
import datetime
import random
import time
def job():
id = random.randint(1, 1000000)
print(f"Started scheduled job: {id}")
time.sleep(10)
print(f"Ended scheduled job: {id}")
def exit_handler():
print("Shutting down scheduler")
scheduler.shutdown(wait=True)
background_executors = {'default': ThreadPoolExecutor(max_workers=2)}
scheduler = BackgroundScheduler(executors=background_executors)
scheduler.add_job(
job,
'interval',
seconds=0.0001,
misfire_grace_time=2,
# using randomization to minimize the chance of all services reloading same time
next_run_time=(datetime.datetime.now() + datetime.timedelta(seconds=random.randint(1, 3))),
max_instances=1,
)
scheduler.start()
atexit.register(exit_handler)
while True:
time.sleep(4)
pass |
I created a fix for it Can I get your 👀 on it! |
Things to check first
I have checked that my issue does not already have a solution in the FAQ
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Version
3.10.4
What happened?
Hello,
I'm trying to create a Python code orchestrator that schedules a function to be called 20 seconds after being triggered. However, every time it runs, the log shows a RuntimeError stating that new tasks cannot be scheduled after the interpreter has shut down.
Interestingly, I used this same code with Python 3.7 without any issues. The only change I've made is updating Python to version 3.10 and APScheduler to version 3.10.4.
Here is the error log:
How can we reproduce the bug?
The text was updated successfully, but these errors were encountered: