Created
August 10, 2011 18:44
-
-
Save emre/1137761 to your computer and use it in GitHub Desktop.
tornado ioloop/asynclient with gevent
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/python | |
| import tornado.httpclient | |
| import tornado.ioloop | |
| import gevent | |
| def on_complete(data): | |
| print data.body[0:10] | |
| def print_head(url): | |
| print ('Starting %s' % url) | |
| http = tornado.httpclient.AsyncHTTPClient() | |
| http.fetch("http://friendfeed.com", on_complete) | |
| jobs = [gevent.spawn(print_head, url) for url in range(0, 50)] | |
| gevent.joinall(jobs) | |
| tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment