diff --git a/Python/MultiProcessing/multiprocessing-demo.py b/Python/MultiProcessing/multiprocessing-demo.py index 05fa38091..4702b718c 100644 --- a/Python/MultiProcessing/multiprocessing-demo.py +++ b/Python/MultiProcessing/multiprocessing-demo.py @@ -1,7 +1,7 @@ import concurrent.futures import time -start = time.perf_counter() + def do_something(seconds): @@ -10,13 +10,19 @@ def do_something(seconds): return f'Done Sleeping...{seconds}' -with concurrent.futures.ProcessPoolExecutor() as executor: - secs = [5, 4, 3, 2, 1] - results = executor.map(do_something, secs) - # for result in results: - # print(result) +if __name__ == '__main__': + + start = time.perf_counter() + + + with concurrent.futures.ProcessPoolExecutor() as executor: + secs = [5, 4, 3, 2, 1] + results = executor.map(do_something, secs) + + for result in results: + print(result) -finish = time.perf_counter() + finish = time.perf_counter() -print(f'Finished in {round(finish-start, 2)} second(s)') + print(f'Finished in {round(finish-start, 2)} second(s)')