From 02618bb22f7755f4c77c8cddcbc568b6540e39bd Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 8 Jul 2025 12:51:08 -0400 Subject: [PATCH] WIP tinkering with strict-eg-tns and cluster API Seems that the way the actor-nursery interacts with the `.trionics.gather_contexts()` API on cancellation makes our `.trionics.collapse_eg()` not work as intended? I need to dig into how `ActorNursery.cancel()` and `.__aexit__()` might be causing this discrepancy.. Consider this a commit-of-my-index type save for rn. --- tests/test_clustering.py | 9 ++++++--- tractor/_clustering.py | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/test_clustering.py b/tests/test_clustering.py index 92362b58..d04e4d5f 100644 --- a/tests/test_clustering.py +++ b/tests/test_clustering.py @@ -25,14 +25,17 @@ def test_empty_mngrs_input_raises() -> None: ) as portals, gather_contexts( - # NOTE: it's the use of inline-generator syntax - # here that causes the empty input. mngrs=( p.open_context(worker) for p in portals.values() ), + # ^^NOTE XXX ^^^ + # it's the use of inline-generator syntax here + # that causes the "empty input" -> ValueError, + # see `._clustering` impl. ), ): - assert 0 + # test should fail if we mk it here! + assert 0, 'Should have raised val-err !?' with pytest.raises(ValueError): trio.run(main) diff --git a/tractor/_clustering.py b/tractor/_clustering.py index 46224d6f..fc4ee68b 100644 --- a/tractor/_clustering.py +++ b/tractor/_clustering.py @@ -55,10 +55,17 @@ async def open_actor_cluster( raise ValueError( 'Number of names is {len(names)} but count it {count}') - async with tractor.open_nursery( - **runtime_kwargs, - ) as an: - async with trio.open_nursery() as n: + async with ( + # tractor.trionics.collapse_eg(), + tractor.open_nursery( + **runtime_kwargs, + ) as an + ): + async with ( + tractor.trionics.collapse_eg(), + trio.open_nursery() as tn, + tractor.trionics.maybe_raise_from_masking_exc() + ): uid = tractor.current_actor().uid async def _start(name: str) -> None: @@ -69,9 +76,8 @@ async def open_actor_cluster( ) for name in names: - n.start_soon(_start, name) + tn.start_soon(_start, name) assert len(portals) == count yield portals - await an.cancel(hard_kill=hard_kill)