diff --git a/tractor/_addr.py b/tractor/_addr.py index 66fc49fc..e7b92461 100644 --- a/tractor/_addr.py +++ b/tractor/_addr.py @@ -40,6 +40,7 @@ from ._state import ( get_rt_dir, current_actor, is_root_process, + _def_tpt_proto, ) if TYPE_CHECKING: @@ -461,9 +462,6 @@ class UDSAddress(Address): os.unlink(self.sockpath) -preferred_transport: str = 'uds' - - _address_types: bidict[str, Type[Address]] = { 'tcp': TCPAddress, 'uds': UDSAddress @@ -525,11 +523,11 @@ def wrap_address( # TODO! BUT THIS WILL MATCH FOR TCP !... # -[ ] so prolly go back to what guille had orig XD # a plain ol' `str`? - case (( - str()|Path(), - int(), - )): - cls = UDSAddress + # case (( + # str()|Path(), + # int(), + # )): + # cls = UDSAddress # classic network socket-address as tuple/list case ( @@ -541,12 +539,14 @@ def wrap_address( # likely an unset UDS or TCP reg address as defaulted in # `_state._runtime_vars['_root_mailbox']` + # + # TODO? figure out when/if we even need this? case ( None | [None, None] ): - cls: Type[Address] = get_address_cls(preferred_transport) + cls: Type[Address] = get_address_cls(_def_tpt_proto) addr: UnwrappedAddress = cls.get_root().unwrap() case _: diff --git a/tractor/_discovery.py b/tractor/_discovery.py index d370eabb..157d229c 100644 --- a/tractor/_discovery.py +++ b/tractor/_discovery.py @@ -33,7 +33,6 @@ from .ipc import _connect_chan, Channel from ._addr import ( UnwrappedAddress, Address, - preferred_transport, wrap_address ) from ._portal import ( @@ -44,6 +43,7 @@ from ._portal import ( from ._state import ( current_actor, _runtime_vars, + _def_tpt_proto, ) if TYPE_CHECKING: @@ -203,7 +203,7 @@ async def maybe_open_portal( async def find_actor( name: str, registry_addrs: list[UnwrappedAddress]|None = None, - enable_transports: list[str] = [preferred_transport], + enable_transports: list[str] = [_def_tpt_proto], only_first: bool = True, raise_on_none: bool = False, diff --git a/tractor/_root.py b/tractor/_root.py index 77344013..f67d746a 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -56,7 +56,6 @@ from ._addr import ( UnwrappedAddress, default_lo_addrs, mk_uuid, - preferred_transport, wrap_address, ) from ._exceptions import ( @@ -139,6 +138,7 @@ async def maybe_block_bp( os.environ.pop('PYTHONBREAKPOINT', None) + @acm async def open_root_actor( *, @@ -148,7 +148,9 @@ async def open_root_actor( # defaults are above arbiter_addr: tuple[UnwrappedAddress]|None = None, - enable_transports: list[str] = [preferred_transport], + enable_transports: list[ + _state.TransportProtocolKey, + ] = [_state._def_tpt_proto], name: str|None = 'root', diff --git a/tractor/_runtime.py b/tractor/_runtime.py index 080768a2..f8356582 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -80,7 +80,6 @@ from ._addr import ( Address, default_lo_addrs, get_address_cls, - preferred_transport, wrap_address, ) from ._context import ( @@ -1322,7 +1321,9 @@ class Actor: ''' if listen_addrs is None: - listen_addrs = default_lo_addrs([preferred_transport]) + listen_addrs = default_lo_addrs([ + _state._def_tpt_proto + ]) else: listen_addrs: list[Address] = [ @@ -1846,7 +1847,7 @@ async def async_main( enable_transports: list[str] = ( maybe_preferred_transports_says_rent or - [preferred_transport] + [_state._def_tpt_proto] ) for transport_key in enable_transports: transport_cls: Type[Address] = get_address_cls( diff --git a/tractor/_state.py b/tractor/_state.py index 4cb7e784..0ec4577e 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -26,6 +26,7 @@ import os from pathlib import Path from typing import ( Any, + Literal, TYPE_CHECKING, ) @@ -164,3 +165,11 @@ def get_rt_dir( if not rtdir.is_dir(): rtdir.mkdir() return rtdir + + +# default IPC transport protocol settings +TransportProtocolKey = Literal[ + 'tcp', + 'uds', +] +_def_tpt_proto: TransportProtocolKey = 'tcp' diff --git a/tractor/_supervise.py b/tractor/_supervise.py index e4017c44..ab3a2a94 100644 --- a/tractor/_supervise.py +++ b/tractor/_supervise.py @@ -34,7 +34,6 @@ import trio from .devx._debug import maybe_wait_for_debugger from ._addr import ( UnwrappedAddress, - preferred_transport, mk_uuid, ) from ._state import current_actor, is_main_process @@ -45,7 +44,9 @@ from ._exceptions import ( is_multi_cancelled, ContextCancelled, ) -from ._root import open_root_actor +from ._root import ( + open_root_actor, +) from . import _state from . import _spawn @@ -138,7 +139,7 @@ class ActorNursery: bind_addrs: list[UnwrappedAddress]|None = None, rpc_module_paths: list[str]|None = None, - enable_transports: list[str] = [preferred_transport], + enable_transports: list[str] = [_state._def_tpt_proto], enable_modules: list[str]|None = None, loglevel: str|None = None, # set log level per subactor debug_mode: bool|None = None,