Skip to content

Instantly share code, notes, and snippets.

@reorx
Created March 26, 2014 06:48
Show Gist options
  • Save reorx/9777949 to your computer and use it in GitHub Desktop.
Save reorx/9777949 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tornado.ioloop import IOLoop
from tornado.httpclient import AsyncHTTPClient
io_loop = IOLoop.instance()
def handle_resp(resp):
print 'callbacks', len(io_loop._callbacks)
print 'timeouts', len(io_loop._timeouts)
print 'resp', resp.request.url, resp.code
if not io_loop._timeouts:
io_loop.stop()
def add_tasks(*args, **kwargs):
print args, kwargs
client = AsyncHTTPClient()
for i in xrange(50):
print 'add job %s' % i
client.fetch('http://www.baidu.com/s?ie=UTF-8&wd=%s' % i, handle_resp)
print 'callbacks', len(io_loop._callbacks)
io_loop.add_callback(add_tasks)
io_loop.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment