-
Notifications
You must be signed in to change notification settings - Fork 184
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
Setting debug mode to "True" in Flask make the jobs run twice. #139
Comments
wait that's why all my functions are running twice?! I've been trying to write if statements to catch duplicate jobs but they run so quickly after the first one that I couldn't filter them out. does removing edit: just tested it and yes that does fix it as a workaround. there goes the last 5 days of troubleshooting |
That happens because Flask in debug mode spawns a child process so that it can restart that process each time your code changes, the new child process initializes and starts a new Context: https://stackoverflow.com/questions/25504149/why-does-running-the-flask-dev-server-run-itself-twice I guess I can detect if the current process is the child one and then I wouldn't allow For now, to work around that, you can either to set Flask reloader |
Thanks @viniciuschiele the use_reloader works fine when running the app locally. As I was using gunicorn to start the app and I found gunicorn also spawns a child process, so to avoid this from happen I just had to modify my Procfile and add:
I thought this could be useful for anyone deploying to a Cloud Platform using a WSGI like gunicorn with Flask. |
When setting up an app to run in debug mode as the snippet added below, flask-apscheduler will run each job scheduled with @scheduler.task('cron', ...) twice.
To replicate add the following Job:
Which will create the following output:
The text was updated successfully, but these errors were encountered: