1
votes

I have a flask app setup to use the gevent WSGIServer in my code. I am also running gunicorn on the command line to start the server.

Should I be using WSGI server in the code when also running with gunicorn? Currently looks like this:

from flask import Flask
from gevent.pywsgi import WSGIServer

application = Flask(__name__)

@application.route("/")
def hello():
    return "hello"

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    WSGIServer(('', port), application).serve_forever()

On the command line I am running gunicorn like:

gunicorn -w 4 myapp:application

Do I need the WSGIServer in my code, or just run it as application.run() on the default flask server?

1

1 Answers

1
votes

According to Standalone WSGI Containers, The gunicorn and gevent.pywsgi are both WSGI Containers, and the gunicorn only reconize the entry named application.
So the code below if __name__ == '__main__': is not useful anymore.
If you want to use gevent,you could do:

gunicorn -k gevent -w 4 myapp:application