How do I close a Server-Send Events connection in Flask?
The below has given an answer using node.js. How to close a "Server-Sent Events"-connection on the server? However, how to do the same thing in python Flask? Well, it depends on the architecture of your app. Let me show you an example (see this code at https://github.com/jkbr/chat/blob/master/app.py ): def event_stream(): pubsub = red.pubsub() pubsub.subscribe('chat') for message in pubsub.listen(): print message yield 'data: %s\n\n' % message['data'] @app.route('/stream') def stream(): return flask.Response(event_stream(), mimetype="text/event-stream") Flask asks a new message to Redis