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)
app.run()launches a development server. It's not meant for production use.yieldintext_gen:import threading; print "Working hard in %s" % threading.currentThread().name