Created
August 12, 2013 09:44
-
-
Save yanmhlv/6209562 to your computer and use it in GitHub Desktop.
Tornado AsyncHTTPClient
This file contains 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
# coding: utf-8 | |
import tornado.ioloop | |
import tornado.web | |
import tornado.httpclient | |
import tornado.autoreload | |
def handler_request(response): | |
if response.error: | |
print response.error | |
else: | |
if response.code == 200: | |
print len(response.body) | |
if response.code == 404: | |
print '404', response.request.url | |
elif response.code == 500: | |
print '500', response.request.url | |
client = tornado.httpclient.AsyncHTTPClient() | |
for url in ['http://vk.com/id%d' % i for i in range(1000)]: | |
client.fetch(url, handler_request) | |
#class MainHandler(tornado.web.RequestHandler): | |
#def get(self): | |
#self.write("Hello, world") | |
if __name__ == '__main__': | |
#application = tornado.web.Application([ | |
#(r"/", MainHandler), | |
#]) | |
#application.listen(port = 5000) | |
tornado.autoreload.start(io_loop=None, check_time=500) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment