Skip to content

Instantly share code, notes, and snippets.

@theSage21
Last active October 12, 2018 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theSage21/25691a832286773733d268f3ab2f8ad0 to your computer and use it in GitHub Desktop.
Save theSage21/25691a832286773733d268f3ab2f8ad0 to your computer and use it in GitHub Desktop.
Tqdm + pool.imap_unordered
from tqdm import tqdm
from multiprocessing import Pool
def myfn(x):
return x ** 2
with Pool() as pool:
args = list(range(1_000_000))
work = pool.imap_unordered(myfn, args, chunksize=100)
results = []
for out in tqdm(work, total=len(args)):
results.append(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment