Skip to content

Instantly share code, notes, and snippets.

@elephantum
Created June 19, 2010 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elephantum/444860 to your computer and use it in GitHub Desktop.
Save elephantum/444860 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment