From 723fb17394becb3bfcb9f5a6f43c48fa75670931 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 27 Dec 2020 11:51:38 -0500 Subject: [PATCH] Add deprecation warning to run() --- tractor/_root.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tractor/_root.py b/tractor/_root.py index 56782bc..7c84af1 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -6,6 +6,7 @@ from functools import partial import importlib from typing import Tuple, Optional, List, Any import typing +import warnings import trio @@ -27,10 +28,20 @@ logger = log.get_logger('tractor') @asynccontextmanager async def open_root_actor( + + # defaults are above arbiter_addr: Tuple[str, int], - name: Optional[str] = None, + + name: Optional[str] = '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[str] = None, + + # enables the multi-process debugger support debug_mode: bool = False, + **kwargs, ) -> typing.Any: """Async entry point for ``tractor``. @@ -75,7 +86,9 @@ async def open_root_actor( logger.warning(f"No actor could be found @ {host}:{port}") # create a local actor and start up its main routine/task - if arbiter_found: # we were able to connect to an arbiter + if arbiter_found: + + # we were able to connect to an arbiter logger.info(f"Arbiter seems to exist @ {host}:{port}") actor = Actor( @@ -149,9 +162,6 @@ def run( _default_arbiter_port, ), - # 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[str] = None, debug_mode: bool = False, **kwargs, @@ -173,6 +183,14 @@ def run( return await async_fn(*args) + warnings.warn( + "`tractor.run()` is now deprecated. `tractor` now" + " implicitly starts the root actor on first actor nursery" + " use. If you want to start the root actor manually, use" + " `tractor.open_root_actor()`.", + DeprecationWarning, + stacklevel=2, + ) return trio.run(_main)