Skip to content

Instantly share code, notes, and snippets.

@alexeygrigorev
Last active September 26, 2025 19:47
Show Gist options
  • Select an option

  • Save alexeygrigorev/4146b2bfed944977a9abd8988d9be604 to your computer and use it in GitHub Desktop.

Select an option

Save alexeygrigorev/4146b2bfed944977a9abd8988d9be604 to your computer and use it in GitHub Desktop.
A function for parallel map with tqdm
from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm
num_threads = 4
pool = ThreadPoolExecutor(max_workers=6)
def map_progress(pool, seq, f):
results = []
with tqdm(total=len(seq)) as progress:
futures = []
for el in seq:
future = pool.submit(f, el)
future.add_done_callback(lambda p: progress.update())
futures.append(future)
for future in futures:
result = future.result()
results.append(result)
return results
# use:
# map_progress(pool, messages, anonymize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment