From ba7b36d88f12092767edb1329f734fde0b8bef42 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 28 Apr 2021 14:35:25 -0400 Subject: [PATCH] De-compact async with tuple on 3.8- Turns out can't use the nicer syntax before python 3.9 (even though it doesn't seem documented anywhere?). Relates to #207 --- tests/test_discovery.py | 46 +++++++++++++++++++++-------------------- tests/test_pubsub.py | 25 ++++++++++------------ 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index d1f84740b..af03ce654 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -268,28 +268,30 @@ async def close_chans_before_nursery( portal2 = await tn.start_actor( 'consumer2', enable_modules=[__name__]) - async with ( - portal1.open_stream_from(stream_forever) as agen1, - portal2.open_stream_from(stream_forever) as agen2, - ): - async with trio.open_nursery() as n: - n.start_soon(streamer, agen1) - n.start_soon(cancel, use_signal, .5) - try: - await streamer(agen2) - finally: - # Kill the root nursery thus resulting in - # normal arbiter channel ops to fail during - # teardown. It doesn't seem like this is - # reliably triggered by an external SIGINT. - # tractor.current_actor()._root_nursery.cancel_scope.cancel() - - # XXX: THIS IS THE KEY THING that happens - # **before** exiting the actor nursery block - - # also kill off channels cuz why not - await agen1.aclose() - await agen2.aclose() + # TODO: compact this back as was in last commit once + # 3.9+, see https://github.com/goodboy/tractor/issues/207 + async with portal1.open_stream_from(stream_forever) as agen1: + async with portal2.open_stream_from( + stream_forever + ) as agen2: + async with trio.open_nursery() as n: + n.start_soon(streamer, agen1) + n.start_soon(cancel, use_signal, .5) + try: + await streamer(agen2) + finally: + # Kill the root nursery thus resulting in + # normal arbiter channel ops to fail during + # teardown. It doesn't seem like this is + # reliably triggered by an external SIGINT. + # tractor.current_actor()._root_nursery.cancel_scope.cancel() + + # XXX: THIS IS THE KEY THING that happens + # **before** exiting the actor nursery block + + # also kill off channels cuz why not + await agen1.aclose() + await agen2.aclose() finally: with trio.CancelScope(shield=True): await trio.sleep(1) diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index 48e65b26e..0d4c62d79 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -60,14 +60,13 @@ def pred(i): def pred(i): return isinstance(i, int) + # TODO: https://github.com/goodboy/tractor/issues/207 async with tractor.find_actor(pub_actor_name) as portal: - async with ( - portal.open_stream_from( - pubber, - topics=which, - seed=seed, - ) as stream - ): + async with portal.open_stream_from( + pubber, + topics=which, + seed=seed, + ) as stream: task_status.started(stream) times = 10 count = 0 @@ -81,13 +80,11 @@ def pred(i): await stream.aclose() - async with ( - portal.open_stream_from( - pubber, - topics=['odd'], - seed=seed, - ) as stream - ): + async with portal.open_stream_from( + pubber, + topics=['odd'], + seed=seed, + ) as stream: await stream.__anext__() count = 0 # async with aclosing(stream) as stream: