From ebd1eb114ebc93e2488d3b2078ae8792e721a452 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 21 Nov 2023 15:18:52 -0500 Subject: [PATCH] Port runtime init to new `tractor.Actor.reg_addrs` related changes --- piker/service/_actor_runtime.py | 36 ++++++++++++++++++++++----------- piker/service/_registry.py | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/piker/service/_actor_runtime.py b/piker/service/_actor_runtime.py index c8f7f5a5..f3899101 100644 --- a/piker/service/_actor_runtime.py +++ b/piker/service/_actor_runtime.py @@ -86,7 +86,7 @@ async def open_piker_runtime( ''' try: # check for existing runtime - actor = tractor.current_actor().uid + actor = tractor.current_actor() except tractor._exceptions.NoRuntime: tractor._state._runtime_vars[ @@ -116,15 +116,16 @@ async def open_piker_runtime( enable_modules=enable_modules, **tractor_kwargs, - ) as _, + ) as actor, open_registry( registry_addrs, ensure_exists=False, ) as addrs, ): + assert actor is tractor.current_actor() yield ( - tractor.current_actor(), + actor, addrs, ) else: @@ -268,28 +269,39 @@ async def maybe_open_pikerd( # async with open_portal(chan) as arb_portal: # yield arb_portal - registry_addrs = registry_addrs or [_default_reg_addr] + registry_addrs: list[tuple[str, int]] = ( + registry_addrs + or [_default_reg_addr] + ) + pikerd_portal: tractor.Portal | None async with ( open_piker_runtime( name=query_name, registry_addrs=registry_addrs, loglevel=loglevel, **kwargs, - ) as _, + ) as (actor, addrs), + # try to attach to any existing (host-local) `pikerd` tractor.find_actor( _root_dname, registry_addrs=registry_addrs, only_first=True, - ) as portal + # raise_on_none=True, + ) as pikerd_portal, + ): - # connect to any existing daemon presuming - # its registry socket was selected. - if ( - portal is not None - ): - yield portal + # connect to any existing remote daemon presuming its + # registry socket was selected. + if pikerd_portal is not None: + + # sanity check that we are actually connecting to + # a remote process and not ourselves. + assert actor.uid != pikerd_portal.chan.uid + assert registry_addrs + + yield pikerd_portal return # presume pikerd role since no daemon could be found at diff --git a/piker/service/_registry.py b/piker/service/_registry.py index a6021717..7391dd49 100644 --- a/piker/service/_registry.py +++ b/piker/service/_registry.py @@ -102,7 +102,7 @@ async def open_registry( not tractor.is_root_process() and not Registry.addrs ): - Registry.addrs.extend(actor._reg_addrs) + Registry.addrs.extend(actor.reg_addrs) if ( ensure_exists