This commit is contained in:
parent
3655a31ac1
commit
ec21971a10
|
@ -22,7 +22,7 @@ source = None
|
||||||
shutdown_event = None
|
shutdown_event = None
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import time
|
import timeit
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
@ -177,7 +177,7 @@ class FileGetter(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
self.result = [0]
|
self.result = [0]
|
||||||
try:
|
try:
|
||||||
if (time.time() - self.starttime) <= 10:
|
if (timeit.default_timer() - self.starttime) <= 10:
|
||||||
f = urlopen(self.url)
|
f = urlopen(self.url)
|
||||||
while 1 and not shutdown_event.isSet():
|
while 1 and not shutdown_event.isSet():
|
||||||
self.result.append(len(f.read(10240)))
|
self.result.append(len(f.read(10240)))
|
||||||
|
@ -191,7 +191,7 @@ class FileGetter(threading.Thread):
|
||||||
def downloadSpeed(files, quiet=False):
|
def downloadSpeed(files, quiet=False):
|
||||||
"""Function to launch FileGetter threads and calculate download speeds"""
|
"""Function to launch FileGetter threads and calculate download speeds"""
|
||||||
|
|
||||||
start = time.time()
|
start = timeit.default_timer()
|
||||||
|
|
||||||
def producer(q, files):
|
def producer(q, files):
|
||||||
for file in files:
|
for file in files:
|
||||||
|
@ -215,14 +215,14 @@ def downloadSpeed(files, quiet=False):
|
||||||
q = Queue(6)
|
q = Queue(6)
|
||||||
prod_thread = threading.Thread(target=producer, args=(q, files))
|
prod_thread = threading.Thread(target=producer, args=(q, files))
|
||||||
cons_thread = threading.Thread(target=consumer, args=(q, len(files)))
|
cons_thread = threading.Thread(target=consumer, args=(q, len(files)))
|
||||||
start = time.time()
|
start = timeit.default_timer()
|
||||||
prod_thread.start()
|
prod_thread.start()
|
||||||
cons_thread.start()
|
cons_thread.start()
|
||||||
while prod_thread.isAlive():
|
while prod_thread.isAlive():
|
||||||
prod_thread.join(timeout=0.1)
|
prod_thread.join(timeout=0.1)
|
||||||
while cons_thread.isAlive():
|
while cons_thread.isAlive():
|
||||||
cons_thread.join(timeout=0.1)
|
cons_thread.join(timeout=0.1)
|
||||||
return (sum(finished) / (time.time() - start))
|
return (sum(finished) / (timeit.default_timer() - start))
|
||||||
|
|
||||||
|
|
||||||
class FilePutter(threading.Thread):
|
class FilePutter(threading.Thread):
|
||||||
|
@ -240,7 +240,7 @@ class FilePutter(threading.Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
if ((time.time() - self.starttime) <= 10 and
|
if ((timeit.default_timer() - self.starttime) <= 10 and
|
||||||
not shutdown_event.isSet()):
|
not shutdown_event.isSet()):
|
||||||
f = urlopen(self.url, self.data)
|
f = urlopen(self.url, self.data)
|
||||||
f.read(11)
|
f.read(11)
|
||||||
|
@ -255,7 +255,7 @@ class FilePutter(threading.Thread):
|
||||||
def uploadSpeed(url, sizes, quiet=False):
|
def uploadSpeed(url, sizes, quiet=False):
|
||||||
"""Function to launch FilePutter threads and calculate upload speeds"""
|
"""Function to launch FilePutter threads and calculate upload speeds"""
|
||||||
|
|
||||||
start = time.time()
|
start = timeit.default_timer()
|
||||||
|
|
||||||
def producer(q, sizes):
|
def producer(q, sizes):
|
||||||
for size in sizes:
|
for size in sizes:
|
||||||
|
@ -279,14 +279,14 @@ def uploadSpeed(url, sizes, quiet=False):
|
||||||
q = Queue(6)
|
q = Queue(6)
|
||||||
prod_thread = threading.Thread(target=producer, args=(q, sizes))
|
prod_thread = threading.Thread(target=producer, args=(q, sizes))
|
||||||
cons_thread = threading.Thread(target=consumer, args=(q, len(sizes)))
|
cons_thread = threading.Thread(target=consumer, args=(q, len(sizes)))
|
||||||
start = time.time()
|
start = timeit.default_timer()
|
||||||
prod_thread.start()
|
prod_thread.start()
|
||||||
cons_thread.start()
|
cons_thread.start()
|
||||||
while prod_thread.isAlive():
|
while prod_thread.isAlive():
|
||||||
prod_thread.join(timeout=0.1)
|
prod_thread.join(timeout=0.1)
|
||||||
while cons_thread.isAlive():
|
while cons_thread.isAlive():
|
||||||
cons_thread.join(timeout=0.1)
|
cons_thread.join(timeout=0.1)
|
||||||
return (sum(finished) / (time.time() - start))
|
return (sum(finished) / (timeit.default_timer() - start))
|
||||||
|
|
||||||
|
|
||||||
def getAttributesByTagName(dom, tagName):
|
def getAttributesByTagName(dom, tagName):
|
||||||
|
@ -400,10 +400,10 @@ def getBestServer(servers):
|
||||||
h = HTTPSConnection(urlparts[1])
|
h = HTTPSConnection(urlparts[1])
|
||||||
else:
|
else:
|
||||||
h = HTTPConnection(urlparts[1])
|
h = HTTPConnection(urlparts[1])
|
||||||
start = time.time()
|
start = timeit.default_timer()
|
||||||
h.request("GET", urlparts[2])
|
h.request("GET", urlparts[2])
|
||||||
r = h.getresponse()
|
r = h.getresponse()
|
||||||
total = (time.time() - start)
|
total = (timeit.default_timer() - start)
|
||||||
except (HTTPError, URLError):
|
except (HTTPError, URLError):
|
||||||
cum.append(3600)
|
cum.append(3600)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue