Skip to content

Instantly share code, notes, and snippets.

@emre
Created August 10, 2011 18:44
Show Gist options
  • Select an option

  • Save emre/1137761 to your computer and use it in GitHub Desktop.

Select an option

Save emre/1137761 to your computer and use it in GitHub Desktop.
tornado ioloop/asynclient with gevent
#!/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