-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5710492
commit a7f3033
Showing
3 changed files
with
28 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Testing multiprocessing + tqdm | ||
https://stackoverflow.com/q/41920124/2229219 | ||
""" | ||
from multiprocessing import cpu_count, freeze_support | ||
from multiprocessing import Pool | ||
from tqdm import tqdm | ||
|
||
def parse_args(): | ||
import argparse | ||
parser = argparse.ArgumentParser(description="Test multiprocessing stuff.") | ||
parser.add_argument("-n", "--number", help="number of iterations", type=int, default=7000000) | ||
args = parser.parse_args() | ||
return args | ||
|
||
def _foo(my_number): | ||
square = my_number * my_number | ||
return square, square | ||
|
||
if __name__ == '__main__': | ||
freeze_support() | ||
print(f"CPU count: {cpu_count()}") | ||
|
||
args = parse_args() | ||
|
||
with Pool() as p: | ||
r1, r2 = zip(*tqdm(p.imap(_foo, range(args.number), chunksize=500), total=args.number)) |