fix silly lock bug, tighten perf tests

This commit is contained in:
Casper da Costa-Luis 2019-11-08 23:05:44 +00:00
parent d301a1237c
commit 213f30288c
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
2 changed files with 8 additions and 7 deletions

View File

@ -1010,7 +1010,7 @@ class tqdm(Comparable):
if not gui:
# Initialize the screen printer
self.sp = self.status_printer(self.fp)
self.refresh()
self.refresh(lock_args=self.lock_args)
# Init the time counter
self.last_print_t = self._time()
@ -1292,7 +1292,8 @@ class tqdm(Comparable):
if lock_args:
if not self._lock.acquire(*lock_args):
return False
self._lock.acquire()
else:
self._lock.acquire()
self.display()
if not nolock:
self._lock.release()

View File

@ -222,8 +222,9 @@ def test_manual_overhead():
def worker(total, blocking=True):
def incr_bar(x):
with closing(StringIO()) as our_file:
with tqdm(total=x, lock_args=None if blocking else (False,),
file=our_file, miniters=1, mininterval=0) as t:
with tqdm(total=x, file=our_file,
lock_args=None if blocking else (False,),
miniters=1, mininterval=0, maxinterval=0) as t:
for i in range(total):
t.update()
return x + 1
@ -242,7 +243,7 @@ def test_lock_args():
import sys
total = 8
subtotal = 10
subtotal = 100
tqdm.set_lock(RLock())
with ThreadPoolExecutor(total) as pool:
@ -256,9 +257,8 @@ def test_lock_args():
with relative_timer() as time_noblock:
res = list(pool.map(worker(subtotal, False), range(total)))
assert sum(res) == sum(range(total)) + total
sys.stderr.write('done ... ')
assert_performance(0.99, 'noblock', time_noblock(), 'tqdm', time_tqdm())
assert_performance(0.2, 'noblock', time_noblock(), 'tqdm', time_tqdm())
@with_setup(pretest, posttest)