gunicorn cannot start flask gunicorn cannot start flask flask flask

gunicorn cannot start flask


To use flask with gunicorn you dont have to run the app (app.run()) since it is a single blocking process which is used only for testing.

Instead pass the flask app module that initiates the variable app (if it is a single file, pass the filename) as argument to gunicorn instead of the external run.py.

This is the right way to use gunicorn with flask.

gunicorn  -b HOST:PORT <MODULE_NAME>:app

Replace MODULE_NAME with the correct module or file name. Use -b flag to set the IP address and port number.


This is what worked for me. Change your run.py file as follows

from app import appif __name__ == "__main__":    app.run(debug=app.config['DEBUG'], port=app.config['PORT'])