Two things might interfere:
You have
debug
set toTrue
, which installs middleware (specifically the Werkzeug debugger) that may break streaming.From the Flask streaming patterns documentation:
Note though that some WSGI middlewares might break streaming, so be careful there in debug environments with profilers and other things you might have enabled.
However, using either
curl
or Chrome on your test code with Flask 0.10.1 and Werkzeug 0.9.4 I see thedata: hi
responses come streaming through properly, regardless of thedebug
flag setting. In other words, your code is working correctly with the most recent versions of the Flask stack.EventSource streams are subject to same-origin policy limits. If you are not loading the HTML page from the same host and port, the request to your Flask server will be denied.
Adding the test page source in the Flask server at a separate route works for me:
@app.route('/') def index(): return '''\ <!doctype html> <html> <head> <script> var source = new EventSource( "/events" ); source.onmessage = function(event) { console.log(event); }; </script> </head> <body> </body> </html> '''