Skip to content

Instantly share code, notes, and snippets.

@fengsp
Created October 28, 2014 11:19
Show Gist options
  • Save fengsp/19e1890fd80e16edc8a4 to your computer and use it in GitHub Desktop.
Save fengsp/19e1890fd80e16edc8a4 to your computer and use it in GitHub Desktop.
Streaming data with Python and Flask
"""
stream
~~~~~~
Streaming data with Python and Flask.
:copyright: (c) 2014 by Shipeng Feng.
:license: BSD.
"""
import time
from flask import Flask, Response
app = Flask(__name__)
@app.route('/')
def index():
def gen():
for c in 'Hello world!':
yield c
time.sleep(0.5)
return Response(gen())
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment