-
-
Save farisalasmary/895f05dbadce1ccb0e93e9dfdaa22285 to your computer and use it in GitHub Desktop.
How to run tqdm in multiple threads
This file contains 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