I am trying to show a separate progress bar for each thread in my program, although I'm also okay with a progress bar that shows the total progress overall. Here is the code:
def cluster(indexes, process_n):
for index in tqdm(indexes, position=process_n, nrows=N_CORES + 1, desc='Process ' + str(process_n)):
# Do something
and
process = multiprocessing.Process(target=cluster, args=(indexes, process_n))
process.start()
processes.append(process)
for process in processes:
process.join()
However, I appear to print extra static progress bars while the function is running. This does not happen when I run only one thread (and hence one progress bar.) As I intend to run this code on 32 threads, the output gets really messy. Here is an example of the terminal output when running 8 threads:
Process 1: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:09<00:00, 13.86it/s]
Process 0: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:09<00:00, 13.25it/s]
Process 7: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.54it/s]
Process 6: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.54it/s]
Process 2: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.50it/s]
Process 5: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.43it/s]
Process 4: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.40it/s]
Process 3: 100%|███████████████████████████████████████████████████████████████████████████████| 127/127 [00:10<00:00, 12.17it/s]
Process 4: 98%|█████████████████████████████████████████████████████████████████████████████▏ | 124/127 [00:10<00:00, 15.24it/s]
Process 3: 99%|██████████████████████████████████████████████████████████████████████████████▍| 126/127 [00:10<00:00, 17.41it/s]
Process 6: 63%|██████████████████████████████████████████████████▍ | 80/127 [00:06<00:04, 11.72it/s]
Please tell me how to fix this. And if the solution involves using something other than multiprocessing.Process then please link some sample code so I can understand how it works. Thanks!