Guest User

Untitled

a guest
May 9th, 2013
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import sys, time, urllib, threading
  2. def reporthook(count, blockSize, totalSize):
  3.     global startTime
  4.     if count == 0:
  5.         startTime= time.time()
  6.         return
  7.     duration = time.time() - startTime
  8.     progressSize = int(count*blockSize)
  9.     if duration!=0:
  10.         speed = int(progressSize / (1024 * duration ))
  11.         percent = int(count*blockSize*100/totalSize)
  12.         sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds passed" % (percent,progressSize/(1024*1024),speed, duration ))
  13.         sys.stdout.flush()
  14.  
  15. class myThread(threading.Thread):
  16.     def __init__(self,url):
  17.         threading.Thread.__init__(self)
  18.         self.url = url
  19.     def run(self):
  20.         urllib.urlretrieve(self.url, reporthook=reporthook)
  21.  
  22. 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"]]
  23. for one in a:
  24.     t = myThread(one[2])
  25.     t.start()
  26.     timep = time.time()
  27.     while True:
  28.         time.sleep(1)
  29.         if time.time() - timep >= 10:
  30.             break
  31.     t._Thread__stop()
Advertisement
Add Comment
Please, Sign In to add comment