diff --git a/fpcup/model.py b/fpcup/model.py index dddc504..18e8c98 100644 --- a/fpcup/model.py +++ b/fpcup/model.py @@ -3,7 +3,7 @@ """ from datetime import date, datetime from itertools import product -from multiprocessing import Pool # Multi-threading +from multiprocessing import Pool from pathlib import Path import geopandas as gpd diff --git a/legacy/test_tqdm_parallel.py b/legacy/test_tqdm_parallel.py deleted file mode 100644 index fd01f2e..0000000 --- a/legacy/test_tqdm_parallel.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Testing multiprocessing + tqdm -https://stackoverflow.com/q/41920124/2229219 -""" - -from multiprocessing import cpu_count -from multiprocessing import Pool -from tqdm import tqdm -import time - -def _foo(my_number): - square = my_number * my_number - return square, square - -if __name__ == '__main__': - print(f"CPU count: {cpu_count()}") - nmax = 7000000 - with Pool() as p: - r1, r2 = zip(*tqdm(p.imap(_foo, range(nmax), chunksize=5), total=nmax)) diff --git a/test/tqdm_parallel.py b/test/tqdm_parallel.py new file mode 100644 index 0000000..86412b2 --- /dev/null +++ b/test/tqdm_parallel.py @@ -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))