Created
February 9, 2012 01:43
-
-
Save gabrielgrant/1776387 to your computer and use it in GitHub Desktop.
Simple wsgi streaming response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install gunicorn | |
gunicorn testapp:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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