Created
May 14, 2014 12:49
-
-
Save vlcinsky/72d56f5be6ed708eb1bd to your computer and use it in GitHub Desktop.
web.py based web server serving data to clients in streaming manner
This file contains hidden or 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 web | |
import time | |
urls = ( | |
"/", "streamer", | |
) | |
app = web.application(urls, globals()) | |
class streamer: | |
def GET(self): | |
web.header('Content-type','text/plain') | |
web.header('Transfer-Encoding','chunked') | |
num_of_lines = 40 | |
delay = 1 | |
for i in range(num_of_lines): | |
yield "line number {i}\n".format(i=i) | |
time.sleep(delay) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment