Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Created December 6, 2019 15:37
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save timothymugayi/1a93a13506ad93d0c67b4bcfe1a763a3 to your computer and use it in GitHub Desktop.
Save timothymugayi/1a93a13506ad93d0c67b4bcfe1a763a3 to your computer and use it in GitHub Desktop.
How to run tqdm in multiple threads
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()
@farisalasmary
Copy link

You're Amazing!
Thank you very much!

@pidement
Copy link

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment