Flask-SocketIO: Concurrency / handling multiple requests not working

Hi @miguelgrinberg,

I am trying to handle multiple concurrent requests using flask_socketio and eventlet. However, it does not work as expected: When function test1() is running, it blocks the execution of function test2() as seen in the output log.

How can I achieve that the server handles both requests simultaneously?

Server (Python):

import eventlet
eventlet.monkey_patch()

from flask import Flask
from flask_socketio import SocketIO

app = Flask(__name__)
socketio = SocketIO(app, async_mode='eventlet')

@socketio.on('test1')
def test1():
    print('test1 started')
    do_complicated_calculation() # takes some time
    print('test1 done')

@socketio.on('test2')
def test2():
    print('test2')

if __name__ == '__main__':
    socketio.run(app)

Client (JavaScript):

import io from 'socket.io-client';

socket = io('http://localhost:5000');
socket.emit('test1');
socket.emit('test2');

Expected Output:

test1 started
test2
test1 done

Actual Output:

test1 started
test1 done
test2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Thanks for your answer! I am a little bit confused … when I used Flask together with @app.route('/test1', methods = ['POST']) I was able to process several request at the same time. So why does socketio not support handling several request at the same time?