Question

Related to this question.

I'm trying to use Flask streaming and having difficulty doing so, it seems my example works on any machine I try it on other than my own. I'm running Flask 0.10.1, Werkzeug 0.9.4, and Python 2.7.6. I have reinstalled Flask and Werkzeug with no effect. If someone could suggest a way to debug this I would be very grateful.

The problem I experience is that data doesnt get sent to the client while the stream is open, it is only sent once the stream is closed (eg in the example below when the generator function returns).

#!/usr/bin/env python

from flask import Flask, Response
from time import sleep

def stream():
    n = 10
    while n > 0:
        yield "data: hi\n\n"
        sleep(0.5)
        n = n - 1

app = Flask(__name__)

@app.route("/events")
def streamSessionEvents():
    return Response(
        stream(),
        mimetype="text/event-stream"
    )

#...also has a route to output html/js client to consume the above

app.run(threaded=True)
Was it helpful?

Solution

Revisited this recently, it was indeed the virus scanner messing with my network traffic.

I'm using Sophos, and found that if I add the address of the machine hosting my Flask application to the virus scanner's "allowed sites" list then my SSE events are received correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top