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, render_template
from flask_socketio import SocketIO, send, emit
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