Created
March 26, 2014 06:48
-
-
Save reorx/9777949 to your computer and use it in GitHub Desktop.
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
#!/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