Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, time, urllib, threading
- def reporthook(count, blockSize, totalSize):
- global startTime
- if count == 0:
- startTime= time.time()
- return
- duration = time.time() - startTime
- progressSize = int(count*blockSize)
- if duration!=0:
- speed = int(progressSize / (1024 * duration ))
- percent = int(count*blockSize*100/totalSize)
- sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds passed" % (percent,progressSize/(1024*1024),speed, duration ))
- sys.stdout.flush()
- class myThread(threading.Thread):
- def __init__(self,url):
- threading.Thread.__init__(self)
- self.url = url
- def run(self):
- urllib.urlretrieve(self.url, reporthook=reporthook)
- a = [["DigitalOcean","198.199.103.13","http://198.199.103.13/100mb.test"],["BuyVM","205.185.112.31","http://speedtest.lv.buyvm.net/100mb.test"]]
- for one in a:
- t = myThread(one[2])
- t.start()
- timep = time.time()
- while True:
- time.sleep(1)
- if time.time() - timep >= 10:
- break
- t._Thread__stop()
Advertisement
Add Comment
Please, Sign In to add comment