diff --git a/setup.py b/setup.py index d26deb9..4cefe67 100755 --- a/setup.py +++ b/setup.py @@ -41,6 +41,9 @@ setup( ], install_requires=[ + # discovery subsys + 'bidict', + # trio related # proper range spec: # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#id5 diff --git a/tractor/_runtime.py b/tractor/_runtime.py index c9e4bfe..67bb0c5 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -40,6 +40,7 @@ from contextlib import ExitStack import warnings from async_generator import aclosing +from bidict import bidict from exceptiongroup import BaseExceptionGroup import trio # type: ignore from trio_typing import TaskStatus @@ -1774,10 +1775,10 @@ class Arbiter(Actor): def __init__(self, *args, **kwargs) -> None: - self._registry: dict[ + self._registry: bidict[ tuple[str, str], tuple[str, int], - ] = {} + ] = bidict({}) self._waiters: dict[ str, # either an event to sync to receiving an actor uid (which @@ -1871,3 +1872,15 @@ class Arbiter(Actor): entry: tuple = self._registry.pop(uid, None) if entry is None: log.warning(f'Request to de-register {uid} failed?') + + + async def delete_sockaddr( + self, + sockaddr: tuple[str, int], + + ) -> tuple[str, str]: + uid: tuple = self._registry.inverse.pop(sockaddr) + log.warning( + f'Deleting registry entry for {sockaddr}@{uid}!' + ) + return uid