Created
December 6, 2019 15:37
-
-
Save timothymugayi/1a93a13506ad93d0c67b4bcfe1a763a3 to your computer and use it in GitHub Desktop.
How to run tqdm in multiple threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from random import randrange | |
from multiprocessing.pool import ThreadPool | |
from tqdm import tqdm | |
def func_call(position, total): | |
text = 'progressbar #{position}'.format(position=position) | |
with tqdm(total=total, position=position, desc=text) as progress: | |
for _ in range(0, total, 5): | |
progress.update(5) | |
time.sleep(randrange(3)) | |
pool = ThreadPool(10) | |
tasks = range(5) | |
for i, url in enumerate(tasks, 1): | |
pool.apply_async(func_call, args=(i, 100)) | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're Amazing!
Thank you very much!