public
Created

  • Download Gist
profile_httpclient.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import time
import tornado.ioloop
import tornado.httpclient
 
import logging
logging.basicConfig(level=logging.DEBUG)
 
io_loop = tornado.ioloop.IOLoop.instance()
 
interrupts_count = 0
 
def ugly_interrupt():
logging.debug('interrupt')
global interrupts_count
interrupts_count += 1
time.sleep(1)
io_loop.add_callback(ugly_interrupt)
 
io_loop.add_callback(ugly_interrupt)
 
http_client = tornado.httpclient.AsyncHTTPClient()
 
start_time = time.time()
def fetch_finished(response):
logging.debug('interrupts: %s', interrupts_count)
logging.debug('time taken: %s', time.time() - start_time)
if not response.error:
logging.debug('file size: %s', len(response.body))
io_loop.stop()
 
# ~1Mb file
http_client.fetch("http://de.archive.ubuntu.com/ubuntu/pool/main/v/vim/vim_7.2.330-1ubuntu3_i386.deb", callback=fetch_finished)
 
io_loop.start()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.