From 74e6eba4ef69bb54f6bfb6dce2ce62ea3b2bbbce Mon Sep 17 00:00:00 2001 From: Dyno Fu Date: Mon, 6 Nov 2017 16:10:09 -0800 Subject: [PATCH] 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. --- examples/parallel_bars.py | 6 +++--- tqdm/_tqdm.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/parallel_bars.py b/examples/parallel_bars.py index 98eb06e0..7efccd0c 100644 --- a/examples/parallel_bars.py +++ b/examples/parallel_bars.py @@ -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)) diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py index b8cf7e9e..2fb31bdc 100755 --- a/tqdm/_tqdm.py +++ b/tqdm/_tqdm.py @@ -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')