Multiple tqdm progress bars with on different processes

Viewed 246

I am trying to create multiple tqdm progress bars which are run by different processes. E.g. 5 processes -> 5 bars -> all in parallel. I managed to achieve something similar. All 5 bars are spawned, however it also starts spawning some extra already existing and dead progress bars. Another problem is that once the working progress bar completes, it disappears.

from time import sleep
from tqdm import tqdm
import concurrent.futures


def _loop_sleep(item, tqdm_pos):
    for _ in tqdm(
        range(1000), 
        total=1000, desc=f'Running {item}', position=tqdm_pos
    ):
        sleep(1)

with concurrent.futures.ProcessPoolExecutor() as executor:
    for item, tqdm_pos in zip(['A', 'B', 'C', 'D'], [0, 2, 4, 6]):
        executor.submit(
            _loop_sleep,
            item, tqdm_pos
        )
        sleep(1)
0 Answers
Related