Skip to content

Instantly share code, notes, and snippets.

@gabrielgrant
Created February 9, 2012 01:43
Show Gist options
  • Save gabrielgrant/1776387 to your computer and use it in GitHub Desktop.
Save gabrielgrant/1776387 to your computer and use it in GitHub Desktop.
Simple wsgi streaming response
pip install gunicorn
gunicorn testapp:app
import time
def app(environ, start_response):
data = 'Hello, World\n'
start_response('200 OK', [
('Content-Type', 'text/plain'),
('Cache-Control', 'no-cache, must-revalidate'),
('Transfer-Encoding', 'chunked'),
])
def response():
for c in data:
time.sleep(0.5)
chunk = '%s\n' % c
print chunk
yield chunk
return response()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment