tractor/examples/service_discovery.py

32 lines
749 B
Python
Raw Normal View History

2021-02-24 18:39:14 +00:00
import trio
import tractor
tractor.log.get_console_log('INFO')
2021-02-24 18:39:14 +00:00
async def main(service_name: str) -> None:
'''
Discover one actor and inspect its registrar connection.
'''
an: tractor.ActorNursery
async with tractor.open_nursery() as an:
await an.start_actor(service_name)
async with tractor.get_registry() as reg_portal:
print(
f'Registrar is listening on {reg_portal.channel}'
)
actor_portal: tractor.Portal
async with tractor.wait_for_actor(
service_name,
) as actor_portal:
print(f'my_service is found at {actor_portal}')
await an.cancel()
if __name__ == '__main__':
2021-02-24 18:39:14 +00:00
trio.run(main, 'some_actor_name')