I'm building python Flask application which uses sockets (flask socketio). Basically, client will send some commands to server, which he wants to execute. Server will execute commands and also send sockets to client commands output.
There is handler function which receives request from user. This function will execute commands and is sending a lot of sockets back to client. To grab stdout and stderr threads are also used.
@socket.on ('run-code')
@authenticated_only
def socket_run_code_request (request):
# run command
# emit socket for each line of output
If flask app is in debug mode, sockets emitted inside function will reach client before function ends (which is desirable). But if debug is off all sockets are somehow queued and are send after function end. No real-time response from server, just
click execute -> wait a minute -> here's your output
instead of:
click execute -> here's a bit of output -> here's a another line -> ...
I've read Flask docs but description of debug is following:
If you enable debug support the server will reload itself on code changes, and it will also provide you with a helpful debugger if things go wrong
Is there any way to tell Flask to send everything right away, or some ideas how to solve this? It may related to flask-socketio plugin for flask
Really much appreciate your feedback :)