diff --git a/examples/parallelism/_concurrent_futures_primes.py b/examples/parallelism/concurrent_futures_primes.py similarity index 61% rename from examples/parallelism/_concurrent_futures_primes.py rename to examples/parallelism/concurrent_futures_primes.py index 7246b864..1ce5ee2a 100644 --- a/examples/parallelism/_concurrent_futures_primes.py +++ b/examples/parallelism/concurrent_futures_primes.py @@ -1,7 +1,19 @@ +''' +The pure-stdlib `concurrent.futures.ProcessPoolExecutor` +primes demo (from the std docs) verbatim; the baseline twin +of `concurrent_actors_primes.py`. + +The `async def main()` + `trio.run()` shim at the bottom only +exists so the docs-example test runner can exercise this +script; the executor code itself is untouched stdlib fare. + +''' import time import concurrent.futures import math +import trio + PRIMES = [ 112272535095293, 112582705942171, @@ -26,7 +38,7 @@ def is_prime(n): return True -def main(): +def check_primes(): with concurrent.futures.ProcessPoolExecutor() as executor: start = time.time() @@ -36,8 +48,14 @@ def main(): print(f'processing took {time.time() - start} seconds') +async def main() -> None: + # thin shim: the pool blocks this (sole) trio task + # which is just fine for a one-shot baseline script. + check_primes() + + if __name__ == '__main__': start = time.time() - main() + trio.run(main) print(f'script took {time.time() - start} seconds')