X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=tests%2Fparallelize_itest.py;h=6ac95380c5a9a132fb7c43172d1a30d0ce59e2ee;hb=f135ec7ae3d7ca347d7489eb28d30b5db98f49de;hp=9d9871053aaa927c1af5508a17db1522b0bbd65a;hpb=6f132c0342ab7aa438ed88d7c5f987cb52d8ca05;p=python_utils.git diff --git a/tests/parallelize_itest.py b/tests/parallelize_itest.py index 9d98710..6ac9538 100755 --- a/tests/parallelize_itest.py +++ b/tests/parallelize_itest.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 -import random import sys import bootstrap import parallelize as p import decorator_utils import executors -import math_utils import smart_future @@ -28,19 +26,19 @@ def compute_factorial_process(n): @p.parallelize(method=p.Method.REMOTE) -def list_primes(n): - """Calculates sum of all primes below given integer n""" - ret = [] +def compute_factorial_remote(n): + total = 1 for x in range(2, n): - ret.append(math_utils.is_prime(x)) - return ret + total *= x + return total @decorator_utils.timed def test_thread_parallelization() -> None: results = [] for _ in range(50): - results.append(compute_factorial_thread(_)) + f = compute_factorial_thread(_) + results.append(f) smart_future.wait_all(results) for future in results: print(f'Thread: {future}') @@ -61,14 +59,11 @@ def test_process_parallelization() -> None: @decorator_utils.timed def test_remote_parallelization() -> None: - results = {} + results = [] for _ in range(50): - n = random.randint(0, 100000) - results[n] = list_primes(n) - tot = 0 - for _ in results[n]: - tot += _ - print(tot) + results.append(compute_factorial_remote(_)) + for result in smart_future.wait_any(results): + print(result) rexecutor = executors.DefaultExecutors().remote_pool() rexecutor.shutdown()