Skip to content

Instantly share code, notes, and snippets.

@jnnks
Created March 4, 2022 11:17
Show Gist options
  • Select an option

  • Save jnnks/bc625004fe42c4bc95c52f004ae5b407 to your computer and use it in GitHub Desktop.

Select an option

Save jnnks/bc625004fe42c4bc95c52f004ae5b407 to your computer and use it in GitHub Desktop.
Simple parallel execution in python with progress reports
from multiprocessing import Pool
def do_work(params):
(i, msg) = params
pass
collection = [(i, "hello") for i in range(100)]
thread_count = 8
with Pool(thread_count) as p:
for i, _ in enumerate(p.imap(do_work, collection), 1):
print(f"progress {(i / len(collection)) * 100:.2f}%", end="\r")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment