Skip to content

Commit

Permalink
Port runtime init to new tractor.Actor.reg_addrs related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Nov 21, 2023
1 parent 29ce8de commit ebd1eb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
36 changes: 24 additions & 12 deletions piker/service/_actor_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion piker/service/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebd1eb1

Please sign in to comment.