简体   繁体   中英

Disable reloader of gunicorn flask application

When I run the flask server in local machine, I use this code

app.run(host='0.0.0.0', port=port,debug=False,use_reloader=False)

I am using BackgroundScheduler so I need reloader to be false othrwise BackgroundScheduler will run twice.

from apscheduler.schedulers.background import BackgroundScheduler

When I deploy to Heroku, I use gunicorn like this

web: gunicorn app:app

So the problem is that reloader is true when using this so BackgroundScheduler has two instances.
So how do I stop reloader for Gunicorn?
Any help will be appreciated.

佛罗里达州

As you can see in above image 2 processes are created.
Thank you in advance

You can just provide the same arguments as command line arguments in heroku:

web: gunicorn app:app --reload=False

This does provide an answer to your question, but it won't solve the issue, as the default value for --reload is already False . You can check that with gunicorn --help .

I think you shouldn't use BackgroundScheduler , but instead use the --daemon flag. As per gunicorn --help : -D, --daemon - Daemonize the Gunicorn process. [False] -D, --daemon - Daemonize the Gunicorn process. [False] . "To Daemonize" means run it as a background process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM