Created
November 10, 2010 16:24
-
-
Save zuriby/671069 to your computer and use it in GitHub Desktop.
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
#!/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