Better tractor startup, runtime detection

supervise
Tyler Goodlet 2021-03-31 14:21:37 -04:00
parent 877db52162
commit b1a1b32315
1 changed files with 23 additions and 27 deletions

View File

@ -68,19 +68,16 @@ async def open_pikerd(
assert _services is None assert _services is None
# XXX: this may open a root actor as well # XXX: this may open a root actor as well
async with tractor.open_nursery( async with tractor.open_root_actor(
# passed through to ``open_root_actor``
# passed through to ``open_root_actor`` name=_root_dname,
name=_root_dname, loglevel=loglevel,
loglevel=loglevel, # TODO: eventually we should be able to avoid
# having the root have more then permissions to
# TODO: eventually we should be able to avoid # spawn other specialized daemons I think?
# having the root have more then permissions to # enable_modules=[__name__],
# spawn other specialized daemons I think? enable_modules=_root_modules,
# enable_modules=[__name__], ) as _, tractor.open_nursery() as actor_nursery:
enable_modules=_root_modules,
) as actor_nursery:
async with trio.open_nursery() as service_nursery: async with trio.open_nursery() as service_nursery:
# assign globally for future daemon/task creation # assign globally for future daemon/task creation
@ -107,22 +104,21 @@ async def maybe_open_pikerd(
try: try:
async with tractor.find_actor(_root_dname) as portal: async with tractor.find_actor(_root_dname) as portal:
if portal is not None: # pikerd exists assert portal is not None
yield portal yield portal
return return
except RuntimeError: # tractor runtime not started yet except (RuntimeError, AssertionError): # tractor runtime not started yet
pass
# assume pikerd role # presume pikerd role
async with open_pikerd( async with open_pikerd(
loglevel, loglevel,
**kwargs, **kwargs,
) as _: ) as _:
# in the case where we're starting up the # in the case where we're starting up the
# tractor-piker runtime stack in **this** process # tractor-piker runtime stack in **this** process
# we return no portal to self. # we return no portal to self.
yield None yield None
# brokerd enabled modules # brokerd enabled modules