Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created May 29, 2019 23:00
Show Gist options
  • Save adamghill/2268ae734cbccc65c2c898cb22b9ffae to your computer and use it in GitHub Desktop.
Save adamghill/2268ae734cbccc65c2c898cb22b9ffae to your computer and use it in GitHub Desktop.
Use tqdm with a thread pool
from multiprocessing.dummy import Pool as ThreadPool
import time
import tqdm
def _square(number):
time.sleep(.5)
return number * number
numbers = list(range(0, 100))
number_of_threads = 14
with ThreadPool(number_of_threads) as pool:
squared_numbers = list(tqdm.tqdm(pool.imap(_square, numbers), total=len(numbers)))
print(squared_numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment