Skip to content

Progress bars jump around with multiprocessing when using the position kwarg #285

@LankyCyril

Description

@LankyCyril
from time import sleep
from tqdm import tqdm
from multiprocessing import Pool, freeze_support

def progresser(n):         
    text = "progresser #{}".format(n)
    for i in tqdm(range(5000), desc=text, position=n):
        sleep(0.001)

if __name__ == '__main__':
    freeze_support()  # for Windows support
    L = list(range(10))
    Pool(len(L)).map(progresser, L)

When running the above script, I get the following (or similar) output. While it is live, progress bars keep changing places, spamming my entire screen with copies of themselves and empty lines.
Tested with Python 2.7.3 from Ubuntu repos, and with Python 3.5.2 from Continuum Analytics (conda).

progresser #0: 100%|█████████| 5000/5000 [00:05<00:00, 916.57it/s]
progresser #1: 100%|█████████| 5000/5000 [00:05<00:00, 916.78it/s]
progresser #3:  90%|████████ | 4487/5000 [00:04<00:00, 914.76it/s]
(venv)$ clear: 100%|█████████| 5000/5000 [00:05<00:00, 910.49it/s]
progresser #4: 100%|█████████| 5000/5000 [00:05<00:00, 910.61it/s]
progresser #6:  95%|████████▌| 4769/5000 [00:05<00:00, 923.10it/s]
progresser #6: 100%|█████████| 5000/5000 [00:05<00:00, 911.17it/s]
progresser #7: 100%|█████████| 5000/5000 [00:05<00:00, 910.28it/s]
progresser #8: 100%|█████████| 5000/5000 [00:05<00:00, 910.75it/s]
progresser #9: 100%|█████████| 5000/5000 [00:05<00:00, 911.04it/s]
progresser #5:  97%|████████▊| 4862/5000 [00:05<00:00, 920.17it/s]
progresser #5: 100%|█████████| 5000/5000 [00:05<00:00, 911.18it/s]
progresser #6:  66%|█████▉   | 3288/5000 [00:03<00:01, 909.58it/s]
progresser #5:  99%|████████▉| 4955/5000 [00:05<00:00, 922.48it/s]
progresser #6:  97%|████████▊| 4862/5000 [00:05<00:00, 920.25it/s]
progresser #1:  79%|███████▏ | 3965/5000 [00:04<00:01, 919.05it/s]
progresser #9:  90%|████████ | 4489/5000 [00:04<00:00, 914.66it/s]
progresser #6:  99%|████████▉| 4955/5000 [00:05<00:00, 922.43it/s]
progresser #7:  68%|██████   | 3378/5000 [00:03<00:01, 908.62it/s]
progresser #4:  99%|████████▉| 4953/5000 [00:05<00:00, 920.60it/s]
progresser #5:  88%|███████▉ | 4398/5000 [00:04<00:00, 919.76it/s]
progresser #4:  82%|███████▍ | 4118/5000 [00:04<00:00, 915.07it/s]


progresser #3:  77%|██████▉  | 3842/5000 [00:04<00:01, 919.17it/s]


progresser #5:  90%|████████ | 4490/5000 [00:04<00:00, 916.05it/s]

progresser #9:  71%|██████▍  | 3563/5000 [00:03<00:01, 915.19it/s]
progresser #5:  66%|█████▉   | 3288/5000 [00:03<00:01, 909.53it/s]

Similar problems, naturally, happen when using the joblib module.

P.S. Notice the (venv)$ prompt closer to the top of the output. That's the prompt drawn by the shell after tqdm is "done." When I execute clear, of course, it simply scrolls down so that's why you still can see everything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions