简体   繁体   中英

Flask-SocketIO with eventlet: Web and Websockets Thread

My setup is flask-socketio with a flask-restful webserver.

Eventlet is installed, so in production mode, eventlet webserver is used.

I understand flask-socketio and eventlet webserver themselves are event-loop based.

Does flask-socketio and eventlet webserver runs on the same eventloop (same thread) or in two different threads?

I think you are confusing the terminology.

The event loop is the task scheduler. This is provided by eventlet, and a single event loop is used for the whole application, including the Flask and the Flask-SocketIO parts.

Each time a request arrives to the eventlet web server, it will allocate a new task for it. So basically each request (be it Flask or Flask-SocketIO, HTTP or WebSocket) will get its own task. Tasks are constantly being created and destroyed as requests are handled.

When you use eventlet, tasks are not threads, they are greenlets, that is why I avoided calling them threads above and used the more generic "task" term. They behave like threads in many ways, but they are not.

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