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
docs_vibed_for_serious
Gud Boi 2026-06-11 15:14:58 -04:00
parent fb8a6b2473
commit f11a74c15d
1 changed files with 20 additions and 2 deletions

View File

@ -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')