From 024b6f6f3135635afb5163315914dab4d394dbcf Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 11 Jun 2026 15:14:58 -0400 Subject: [PATCH] Un-hide stdlib primes example, add `trio` shim Rename `parallelism/_concurrent_futures_primes.py` -> `concurrent_futures_primes.py` so the example-runner (`test_docs_examples.py`) stops skipping it (leading `_` = excluded) and CI finally exercises the `concurrent.futures` baseline we compare against in the new parallelism guide. Deats, - keep the original executor code verbatim in a sync `check_primes()` fn for clean docs excerpting, - add module docstring + zero-arg `async def main()` + `trio.run(main)` guard per the runner conventions. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- ...primes.py => concurrent_futures_primes.py} | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) rename examples/parallelism/{_concurrent_futures_primes.py => concurrent_futures_primes.py} (61%) 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')