Skip to content Skip to sidebar Skip to footer

Using Multiple Bars

I would like to have two independent progress bars. This is a minimal example where if I use two bars they are not updated properly. Instead, new bars are created. import time from

Solution 1:

Try using the position parameter when initialising the bars:

pbar1 = tqdm(total=100, position=1)
pbar2 = tqdm(total=200, position=0)

From the tqdm GitHub page:

position : int, optional

Specify the line offset to print this bar (starting from 0) Automatic if unspecified. Useful to manage multiple bars at once (eg, from threads).

Solution 2:

Here I have some examples of nested progress bar, examples of tqdm and some issues I have with it in general; from which I highlight the following code snippet that yields to two nice nested progress bars.

def test48():
  with tqdm.notebook.trange(3, position=0, desc='Outter') as outter_range:
    for i in outter_range:
      leave = i == len(outter_range) - 1for _ in tqdm.notebook.trange(3, position=1, leave=leave, desc='Inner'):
        sleep(.3)

enter image description here

Post a Comment for "Using Multiple Bars"