I’ve started working a lot with Flask SocketIO in Python with Eventlet and are looking for a solution to handle concurrent requests/threading. I’ve seen that it is possible with gevent, but how can I do it if I use eventlet?
2 Answers
The eventlet web server supports concurrency through greenlets, same as gevent. No need for you to do anything, concurrency is always enabled.
2 Comments
You could use gunicorn or its analogs to launch the app in production mode with several workers.
As said here:
gunicorn --worker-class eventlet -w 5 module:app
Where the number after -w is the number of workers, module is your flask-socketio server module, and app is the flask app (app = flask.Flask(__name__)). Each worker is a process busy with handling incoming requests, so you will have concurrency. If the tasks your app does take significant time, the worker doing that task will be irresponsive while doing it.
Note: if you launch your app this way, the if __name__ == '__main__': part will be ignored, it seems that your module will be imported. And you don't need to call app.run yourself in the module in this case
gunicorn. There is more info on this matter in the flask-socketio docs page flask-socketio.readthedocs.io/en/latest You could set a number of workers there for concurrency