Fix overlap of nested progressbar

The problem is exhibitable with the modified examples/parallel_bars.py,
the fix is simple check pos is not None rather otherwise will fall into
the trap of 0.
This commit is contained in:
Dyno Fu 2017-11-06 16:10:09 -08:00 committed by Casper da Costa-Luis
parent f66d9923d1
commit 74e6eba4ef
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
2 changed files with 5 additions and 5 deletions

View File

@ -8,7 +8,7 @@ L = list(range(9))
def progresser(n):
interval = 0.001 / (n + 2)
interval = 0.001 / (len(L) - n + 2)
total = 5000
text = "#{}, est. {:<04.2}s".format(n, interval * total)
for _ in tqdm(range(total), desc=text, position=n):
@ -21,9 +21,9 @@ if __name__ == '__main__':
initializer=tqdm.set_lock,
initargs=(RLock(),))
p.map(progresser, L)
print("\n" * (len(L) - 2))
print("\n" * len(L))
# alternatively, on UNIX, just use the default internal lock
p = Pool(len(L))
p.map(progresser, L)
print("\n" * (len(L) - 2))
print("\n" * len(L))

View File

@ -1107,13 +1107,13 @@ Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
# stats for overall rate (no weighted average)
self.avg_time = None
self.sp(self.__repr__())
if pos:
if pos is not None:
self.moveto(-pos)
else:
fp_write('\n')
else:
self.sp('') # clear up last bar
if pos:
if pos is not None:
self.moveto(-pos)
else:
fp_write('\r')