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
parent
4313ac256c
commit
024b6f6f31
|
|
@ -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 time
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
import trio
|
||||||
|
|
||||||
PRIMES = [
|
PRIMES = [
|
||||||
112272535095293,
|
112272535095293,
|
||||||
112582705942171,
|
112582705942171,
|
||||||
|
|
@ -26,7 +38,7 @@ def is_prime(n):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def check_primes():
|
||||||
with concurrent.futures.ProcessPoolExecutor() as executor:
|
with concurrent.futures.ProcessPoolExecutor() as executor:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
|
|
@ -36,8 +48,14 @@ def main():
|
||||||
print(f'processing took {time.time() - start} seconds')
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
main()
|
trio.run(main)
|
||||||
print(f'script took {time.time() - start} seconds')
|
print(f'script took {time.time() - start} seconds')
|
||||||
Loading…
Reference in New Issue