2

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?

1
  • I think you should look at deployment tools for flask, like 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 Commented Feb 4, 2018 at 18:28

2 Answers 2

5

The eventlet web server supports concurrency through greenlets, same as gevent. No need for you to do anything, concurrency is always enabled.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Miguel, good to know. Although,do you think the application would somehow benefit of using gunicorn in addition to eventlet as worker? And does eventlet support parallelism?
I wouldn't say there is a benefit. Eventlet comes with a greenlet based WSGI server, and gunicorn too. You can use either one with Flask-SocketIO. Eventlet, like gevent, runs in a single thread and uses cooperative multi-tasking.
-1

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

1 Comment

I'm downvoting this because it is incorrect. You can't use more than one worker with gunicorn, because it lacks "sticky session" support. Sticky sessions are required for the Socket.IO protocol to work with multiple workers. The documentation covers the valid deployment approaches for Flask-SocketIO applications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.