Created
May 29, 2019 23:00
-
-
Save adamghill/2268ae734cbccc65c2c898cb22b9ffae to your computer and use it in GitHub Desktop.
Use tqdm with a thread pool
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
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