Created
June 19, 2010 12:34
-
-
Save elephantum/444860 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
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