Created
August 19, 2012 09:47
-
-
Save cjgiridhar/3394007 to your computer and use it in GitHub Desktop.
Tornado - Asynchronous
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 tornado.ioloop | |
import tornado.web | |
import httplib2 | |
httplib2.debuglevel=1 | |
http = httplib2.Http() | |
class AsyncHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): | |
self.response, self.content = http.request("http://google.co.in", "GET") | |
self._async_callback(self.response) | |
def _async_callback(self, response): | |
print response.keys() | |
self.finish() | |
tornado.ioloop.IOLoop.instance().stop() | |
application = tornado.web.Application([ | |
(r"/", AsyncHandler)], debug=True) | |
if __name__ == "__main__": | |
application.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