Fixed threadding errors from issue #37

This commit is contained in:
Jacob Mansfield 2013-10-08 09:31:05 +01:00 committed by root
parent 35c7e6d6b5
commit ae2db04ae5
1 changed files with 10 additions and 10 deletions

View File

@ -146,7 +146,7 @@ class FileGetter(threading.Thread):
try: try:
if (time.time() - self.starttime) <= 10: if (time.time() - self.starttime) <= 10:
f = urlopen(self.url) f = urlopen(self.url)
while 1 and not shutdown_event.is_set(): while 1 and not shutdown_event.isSet():
self.result.append(len(f.read(10240))) self.result.append(len(f.read(10240)))
if self.result[-1] == 0: if self.result[-1] == 0:
break break
@ -163,7 +163,7 @@ def downloadSpeed(files, quiet=False):
thread = FileGetter(file, start) thread = FileGetter(file, start)
thread.start() thread.start()
q.put(thread, True) q.put(thread, True)
if not quiet and not shutdown_event.is_set(): if not quiet and not shutdown_event.isSet():
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
@ -172,7 +172,7 @@ def downloadSpeed(files, quiet=False):
def consumer(q, total_files): def consumer(q, total_files):
while len(finished) < total_files: while len(finished) < total_files:
thread = q.get(True) thread = q.get(True)
while thread.is_alive(): while thread.isAlive():
thread.join(timeout=0.1) thread.join(timeout=0.1)
finished.append(sum(thread.result)) finished.append(sum(thread.result))
del thread del thread
@ -183,9 +183,9 @@ def downloadSpeed(files, quiet=False):
start = time.time() start = time.time()
prod_thread.start() prod_thread.start()
cons_thread.start() cons_thread.start()
while prod_thread.is_alive(): while prod_thread.isAlive():
prod_thread.join(timeout=0.1) prod_thread.join(timeout=0.1)
while cons_thread.is_alive(): 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)/(time.time()-start))
@ -204,7 +204,7 @@ class FilePutter(threading.Thread):
def run(self): def run(self):
try: try:
if ((time.time() - self.starttime) <= 10 and if ((time.time() - self.starttime) <= 10 and
not shutdown_event.is_set()): not shutdown_event.isSet()):
f = urlopen(self.url, self.data) f = urlopen(self.url, self.data)
f.read(11) f.read(11)
f.close() f.close()
@ -223,7 +223,7 @@ def uploadSpeed(url, sizes, quiet=False):
thread = FilePutter(url, start, size) thread = FilePutter(url, start, size)
thread.start() thread.start()
q.put(thread, True) q.put(thread, True)
if not quiet and not shutdown_event.is_set(): if not quiet and not shutdown_event.isSet():
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
@ -232,7 +232,7 @@ def uploadSpeed(url, sizes, quiet=False):
def consumer(q, total_sizes): def consumer(q, total_sizes):
while len(finished) < total_sizes: while len(finished) < total_sizes:
thread = q.get(True) thread = q.get(True)
while thread.is_alive(): while thread.isAlive():
thread.join(timeout=0.1) thread.join(timeout=0.1)
finished.append(thread.result) finished.append(thread.result)
del thread del thread
@ -243,9 +243,9 @@ def uploadSpeed(url, sizes, quiet=False):
start = time.time() start = time.time()
prod_thread.start() prod_thread.start()
cons_thread.start() cons_thread.start()
while prod_thread.is_alive(): while prod_thread.isAlive():
prod_thread.join(timeout=0.1) prod_thread.join(timeout=0.1)
while cons_thread.is_alive(): 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)/(time.time()-start))