Skip to content

Instantly share code, notes, and snippets.

@zuriby
Created November 10, 2010 16:24
Show Gist options
  • Save zuriby/671069 to your computer and use it in GitHub Desktop.
Save zuriby/671069 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
class StreamHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
#self.set_header("Content-Type", "application/ogg+ogg")
self.ioloop = tornado.ioloop.IOLoop.instance()
self.pipe = os.popen('cat foo.log')
self.ioloop.add_handler(
self.pipe.fileno(),
self.async_callback(self.on_response),
self.ioloop.READ )
def on_response(self,fd,events):
for line in self.pipe:
self.write( line )
self.ioloop.remove_handler(fd)
self.finish()
application = tornado.web.Application([
(r"/", StreamHandler),
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment