From 9da3b63644bd5a5bed8d8fd195d017fc6d240d1b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 19 Oct 2023 12:40:37 -0400 Subject: [PATCH] Change remaining internals to use `Actor.reg_addrs` --- tractor/_discovery.py | 32 +++++++++++++++++++------------- tractor/_root.py | 9 ++++++--- tractor/_spawn.py | 2 +- tractor/_supervise.py | 2 +- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tractor/_discovery.py b/tractor/_discovery.py index 070321b..b5f4716 100644 --- a/tractor/_discovery.py +++ b/tractor/_discovery.py @@ -133,14 +133,12 @@ async def query_actor( ) regaddr: list[tuple[str, int]] = arbiter_sockaddr - regstr: Portal - async with get_registry( - *(regaddr or actor._reg_addrs[0]) - ) as regstr: - + reg_portal: Portal + regaddr: tuple[str, int] = regaddr or actor.reg_addrs[0] + async with get_registry(*regaddr) as reg_portal: # TODO: return portals to all available actors - for now # just the last one that registered - sockaddr: tuple[str, int] = await regstr.run_from_ns( + sockaddr: tuple[str, int] = await reg_portal.run_from_ns( 'self', 'find_actor', name=name, @@ -155,6 +153,7 @@ async def find_actor( registry_addrs: list[tuple[str, int]] | None = None, only_first: bool = True, + raise_on_none: bool = False, ) -> AsyncGenerator[ Portal | list[Portal] | None, @@ -207,13 +206,20 @@ async def find_actor( async with gather_contexts( mngrs=maybe_portals, - ) as maybe_portals: - print(f'Portalz: {maybe_portals}') - if not maybe_portals: + ) as portals: + # log.runtime( + # 'Gathered portals:\n' + # f'{portals}' + # ) + if not portals: + if raise_on_none: + raise RuntimeError( + f'No {name} found registered @ {registry_addrs}' + ) yield None return - portals: list[Portal] = list(maybe_portals) + portals: list[Portal] = list(portals) if only_first: yield portals[0] @@ -250,9 +256,9 @@ async def wait_for_actor( # TODO: use `.trionics.gather_contexts()` like # above in `find_actor()` as well? - async with get_registry( - *(registry_addr or actor._reg_addrs[0]), # first if not passed - ) as reg_portal: + reg_portal: Portal + regaddr: tuple[str, int] = registry_addr or actor.reg_addrs[0] + async with get_registry(*regaddr) as reg_portal: sockaddrs = await reg_portal.run_from_ns( 'self', 'wait_for_actor', diff --git a/tractor/_root.py b/tractor/_root.py index a36a7e7..5615bb6 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -85,7 +85,7 @@ async def open_root_actor( enable_modules: list | None = None, rpc_module_paths: list | None = None, -) -> typing.Any: +) -> Actor: ''' Runtime init entry point for ``tractor``. @@ -130,7 +130,7 @@ async def open_root_actor( registry_addrs: list[tuple[str, int]] = ( registry_addrs - or + or _default_lo_addrs ) assert registry_addrs @@ -195,7 +195,10 @@ async def open_root_actor( async with trio.open_nursery() as tn: for addr in registry_addrs: - tn.start_soon(ping_tpt_socket, addr) + tn.start_soon( + ping_tpt_socket, + tuple(addr), # TODO: just drop this requirement? + ) trans_bind_addrs: list[tuple[str, int]] = [] diff --git a/tractor/_spawn.py b/tractor/_spawn.py index aede3b7..e55e59f 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -423,7 +423,7 @@ async def trio_proc( await chan.send({ '_parent_main_data': subactor._parent_main_data, 'enable_modules': subactor.enable_modules, - '_reg_addrs': subactor._reg_addrs, + 'reg_addrs': subactor.reg_addrs, 'bind_addrs': bind_addrs, '_runtime_vars': _runtime_vars, }) diff --git a/tractor/_supervise.py b/tractor/_supervise.py index 7851d9f..364d79c 100644 --- a/tractor/_supervise.py +++ b/tractor/_supervise.py @@ -149,7 +149,7 @@ class ActorNursery: loglevel=loglevel, # verbatim relay this actor's registrar addresses - registry_addrs=current_actor()._reg_addrs, + registry_addrs=current_actor().reg_addrs, ) parent_addr = self._actor.accept_addr assert parent_addr