Created
March 4, 2022 11:17
-
-
Save jnnks/bc625004fe42c4bc95c52f004ae5b407 to your computer and use it in GitHub Desktop.
Simple parallel execution in python with progress reports
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 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