From c54b8ca4bad912b64ad73b30d8a8c51f830da874 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 13 Jan 2023 16:57:55 -0500 Subject: [PATCH 1/3] Begin deprecation of `arbiter_addr` -> `registry_addr` --- tractor/_root.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tractor/_root.py b/tractor/_root.py index cb405f5..dfb86f2 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -58,11 +58,12 @@ logger = log.get_logger('tractor') @asynccontextmanager async def open_root_actor( + *, # defaults are above - arbiter_addr: Optional[tuple[str, int]] = ( - _default_arbiter_host, - _default_arbiter_port, - ), + arbiter_addr: tuple[str, int] | None = None, + + # defaults are above + registry_addr: tuple[str, int] | None = None, name: Optional[str] = 'root', @@ -112,9 +113,21 @@ async def open_root_actor( if start_method is not None: _spawn.try_set_start_method(start_method) - arbiter_addr = (host, port) = arbiter_addr or ( - _default_arbiter_host, - _default_arbiter_port, + if arbiter_addr is not None: + warnings.warn( + '`arbiter_addr` is now deprecated and has been renamed to' + '`registry_addr`.\nUse that instead..', + DeprecationWarning, + stacklevel=2, + ) + + registry_addr = (host, port) = ( + registry_addr + or arbiter_addr + or ( + _default_arbiter_host, + _default_arbiter_port, + ) ) loglevel = (loglevel or log._default_loglevel).upper() @@ -170,7 +183,7 @@ async def open_root_actor( actor = Actor( name or 'anonymous', - arbiter_addr=arbiter_addr, + arbiter_addr=registry_addr, loglevel=loglevel, enable_modules=enable_modules, ) @@ -186,7 +199,7 @@ async def open_root_actor( actor = Arbiter( name or 'arbiter', - arbiter_addr=arbiter_addr, + arbiter_addr=registry_addr, loglevel=loglevel, enable_modules=enable_modules, ) @@ -252,7 +265,7 @@ def run_daemon( # runtime kwargs name: Optional[str] = 'root', - arbiter_addr: tuple[str, int] = ( + registry_addr: tuple[str, int] = ( _default_arbiter_host, _default_arbiter_port, ), @@ -279,7 +292,7 @@ def run_daemon( async def _main(): async with open_root_actor( - arbiter_addr=arbiter_addr, + arbiter_addr=registry_addr, name=name, start_method=start_method, debug_mode=debug_mode, From 121a8cc891e60b79de5f22e07b50ff432416a1b7 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 26 Jan 2023 12:43:06 -0500 Subject: [PATCH 2/3] Drop `Optional` usage from root mod --- tractor/_root.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tractor/_root.py b/tractor/_root.py index dfb86f2..840b288 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -24,9 +24,6 @@ import importlib import logging import os import signal -from typing import ( - Optional, -) import typing import warnings @@ -65,21 +62,21 @@ async def open_root_actor( # defaults are above registry_addr: tuple[str, int] | None = None, - name: Optional[str] = 'root', + name: str | None = 'root', # either the `multiprocessing` start method: # https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods # OR `trio` (the new default). - start_method: Optional[_spawn.SpawnMethodKey] = None, + start_method: _spawn.SpawnMethodKey | None = None, # enables the multi-process debugger support debug_mode: bool = False, # internal logging - loglevel: Optional[str] = None, + loglevel: str | None = None, - enable_modules: Optional[list] = None, - rpc_module_paths: Optional[list] = None, + enable_modules: list | None = None, + rpc_module_paths: list | None = None, ) -> typing.Any: ''' @@ -93,7 +90,7 @@ async def open_root_actor( # attempt to retreive ``trio``'s sigint handler and stash it # on our debugger lock state. - _debug.Lock._trio_handler = signal.getsignal(signal.SIGINT) + _debug.Lock._trio_handler = signal.getsignal(signal.SIGINT) # mark top most level process as root actor _state._runtime_vars['_is_root'] = True @@ -173,7 +170,7 @@ async def open_root_actor( except OSError: # TODO: make this a "discovery" log level? - logger.warning(f"No actor could be found @ {host}:{port}") + logger.warning(f"No actor registry found @ {host}:{port}") # create a local actor and start up its main routine/task if arbiter_found: @@ -264,13 +261,13 @@ def run_daemon( enable_modules: list[str], # runtime kwargs - name: Optional[str] = 'root', + name: str | None = 'root', registry_addr: tuple[str, int] = ( _default_arbiter_host, _default_arbiter_port, ), - start_method: Optional[str] = None, + start_method: str | None = None, debug_mode: bool = False, **kwargs From 606efa5bb7da1bc2ae175e154ea99023efa017b8 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 26 Jan 2023 12:43:32 -0500 Subject: [PATCH 3/3] Adjust daemon command to use new `registry_addr` --- tests/conftest.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9b26de6..af42b85 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -205,16 +205,22 @@ def sig_prog(proc, sig): @pytest.fixture -def daemon(loglevel, testdir, arb_addr): - """Run a daemon actor as a "remote arbiter". - """ +def daemon( + loglevel: str, + testdir, + arb_addr: tuple[str, int], +): + ''' + Run a daemon actor as a "remote arbiter". + + ''' if loglevel in ('trace', 'debug'): # too much logging will lock up the subproc (smh) loglevel = 'info' cmdargs = [ sys.executable, '-c', - "import tractor; tractor.run_daemon([], arbiter_addr={}, loglevel={})" + "import tractor; tractor.run_daemon([], registry_addr={}, loglevel={})" .format( arb_addr, "'{}'".format(loglevel) if loglevel else None)