Skip to content

Instantly share code, notes, and snippets.

@pidement
Forked from timothymugayi/tqdm_threadpool.py
Created January 12, 2023 01:21
Show Gist options
  • Save pidement/d863cc5552c3a0c608f46e623e3c460c to your computer and use it in GitHub Desktop.
Save pidement/d863cc5552c3a0c608f46e623e3c460c 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
import tqdm
def func_call(position, total):
text = 'progressbar #{position}'.format(position=position)
with tqdm.notebook.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