Skip to content

Instantly share code, notes, and snippets.

@vlcinsky
Created May 14, 2014 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlcinsky/72d56f5be6ed708eb1bd to your computer and use it in GitHub Desktop.
Save vlcinsky/72d56f5be6ed708eb1bd to your computer and use it in GitHub Desktop.
web.py based web server serving data to clients in streaming manner
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