Port runtime init to new `tractor.Actor.reg_addrs` related changes

distribute_dis
Tyler Goodlet 2023-11-21 15:18:52 -05:00
parent 29ce8de462
commit ebd1eb114e
2 changed files with 25 additions and 13 deletions

View File

@ -86,7 +86,7 @@ async def open_piker_runtime(
''' '''
try: try:
# check for existing runtime # check for existing runtime
actor = tractor.current_actor().uid actor = tractor.current_actor()
except tractor._exceptions.NoRuntime: except tractor._exceptions.NoRuntime:
tractor._state._runtime_vars[ tractor._state._runtime_vars[
@ -116,15 +116,16 @@ async def open_piker_runtime(
enable_modules=enable_modules, enable_modules=enable_modules,
**tractor_kwargs, **tractor_kwargs,
) as _, ) as actor,
open_registry( open_registry(
registry_addrs, registry_addrs,
ensure_exists=False, ensure_exists=False,
) as addrs, ) as addrs,
): ):
assert actor is tractor.current_actor()
yield ( yield (
tractor.current_actor(), actor,
addrs, addrs,
) )
else: else:
@ -268,28 +269,39 @@ async def maybe_open_pikerd(
# async with open_portal(chan) as arb_portal: # async with open_portal(chan) as arb_portal:
# yield 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 ( async with (
open_piker_runtime( open_piker_runtime(
name=query_name, name=query_name,
registry_addrs=registry_addrs, registry_addrs=registry_addrs,
loglevel=loglevel, loglevel=loglevel,
**kwargs, **kwargs,
) as _, ) as (actor, addrs),
# try to attach to any existing (host-local) `pikerd`
tractor.find_actor( tractor.find_actor(
_root_dname, _root_dname,
registry_addrs=registry_addrs, registry_addrs=registry_addrs,
only_first=True, only_first=True,
) as portal # raise_on_none=True,
) as pikerd_portal,
): ):
# connect to any existing daemon presuming # connect to any existing remote daemon presuming its
# its registry socket was selected. # registry socket was selected.
if ( if pikerd_portal is not None:
portal is not None
): # sanity check that we are actually connecting to
yield portal # a remote process and not ourselves.
assert actor.uid != pikerd_portal.chan.uid
assert registry_addrs
yield pikerd_portal
return return
# presume pikerd role since no daemon could be found at # presume pikerd role since no daemon could be found at

View File

@ -102,7 +102,7 @@ async def open_registry(
not tractor.is_root_process() not tractor.is_root_process()
and not Registry.addrs and not Registry.addrs
): ):
Registry.addrs.extend(actor._reg_addrs) Registry.addrs.extend(actor.reg_addrs)
if ( if (
ensure_exists ensure_exists