From f7e1c526c53a91ad81b5661a96ba9e112829b08f Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 24 Jan 2021 13:14:17 -0500 Subject: [PATCH] Add `aclosing()` around asyn gen loop --- examples/parallelism/concurrent_actors_primes.py | 8 +++++--- examples/{ => parallelism}/concurrent_futures_primes.py | 0 2 files changed, 5 insertions(+), 3 deletions(-) rename examples/{ => parallelism}/concurrent_futures_primes.py (100%) diff --git a/examples/parallelism/concurrent_actors_primes.py b/examples/parallelism/concurrent_actors_primes.py index 1f5fe48..3ff8dab 100644 --- a/examples/parallelism/concurrent_actors_primes.py +++ b/examples/parallelism/concurrent_actors_primes.py @@ -16,6 +16,7 @@ import time import tractor import trio +from async_generator import aclosing PRIMES = [ @@ -103,10 +104,11 @@ async def main(): async with worker_pool() as actor_map: start = time.time() - # for number, prime in zip(PRIMES, executor.map(is_prime, PRIMES)): - async for number, prime in actor_map(is_prime, PRIMES): - print(f'{number} is prime: {prime}') + async with aclosing(actor_map(is_prime, PRIMES)) as results: + async for number, prime in results: + + print(f'{number} is prime: {prime}') print(f'processing took {time.time() - start} seconds') diff --git a/examples/concurrent_futures_primes.py b/examples/parallelism/concurrent_futures_primes.py similarity index 100% rename from examples/concurrent_futures_primes.py rename to examples/parallelism/concurrent_futures_primes.py