Threaded Flask application not working as expected
flask, python
Solution
@Lukas was right.
I was debugging in Google Chrome with two tabs. Apparently Chrome is trying to be smart by using the socket same for both tabs. How Chrome handles that can be changed with the `-socket-reuse-policy` flag when starting Chrome.
An easier way to test is by using different hostname in each tab or by using `curl -N` (`-N` flag for no buffer to see the streaming). Doing that it did indeed work as expected.
Problem
I want my flask application to be able to process more than one call at the same time. I've been testing running with `threaded=True` or `processes=3` with the code below but when I make two calls to the server the later always have to wait for the first one to complete. I know that it's recommended to deploy the application on a more sophisticated WSGI container but for now I just want my small app to be able to process 2 calls at once. ``` from flask import Flask, Response, stream_with_context from time import sleep app = Flask(__name__) def text_gen(message): for c in message: yield c sleep(1) @app.route("/") def hello(): stream = text_gen('Hello World') return Response(stream_with_context(stream)) if __name__ == "__main__": app.run(host='0.0.0.0', port=8080, debug=True, threaded=True) ```