Skip to content

Instantly share code, notes, and snippets.

@PiotrDabrowskey
Last active December 13, 2019 13:58
Show Gist options
  • Save PiotrDabrowskey/1784f50f6bd70cceaaf890f1b99bf453 to your computer and use it in GitHub Desktop.
Save PiotrDabrowskey/1784f50f6bd70cceaaf890f1b99bf453 to your computer and use it in GitHub Desktop.
python multiprocess tqdm example
from multiprocess import Pool
def tqdm_multiprocessing_map(fun, sequence, unordered=False, unpack_args=False, debug=False):
if unpack_args:
def fun_wrapper(args):
return fun(*args)
else:
fun_wrapper = fun
try:
total = len(sequence)
except TypeError:
sequence = list(sequence)
total = len(sequence)
if debug:
return list(map(fun_wrapper, sequence))
with Pool() as pool:
map_fun = pool.imap_unordered if unordered else pool.imap
sequence = map_fun(fun_wrapper, sequence)
sequence = tqdm(sequence, total=total, leave=False)
return list(sequence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment