Remove `tractor.run()` once and for all

It's been deprecated for a while now and all docs and tests have been
changed.

Closes #183
we_bein_all_matchy
Tyler Goodlet 2022-09-15 16:15:17 -04:00
parent 9aef03772a
commit ad19bf2cf1
3 changed files with 33 additions and 55 deletions

View File

@ -23,13 +23,6 @@ async def test_no_arbitter():
pass
def test_no_main():
"""An async function **must** be passed to ``tractor.run()``.
"""
with pytest.raises(TypeError):
tractor.run(None)
@tractor_test
async def test_self_is_registered(arb_addr):
"Verify waiting on the arbiter to register itself using the standard api."

View File

@ -36,7 +36,10 @@ from ._discovery import (
query_actor,
)
from ._supervise import open_nursery
from ._state import current_actor, is_root_process
from ._state import (
current_actor,
is_root_process,
)
from ._exceptions import (
RemoteActorError,
ModuleNotExposed,
@ -44,7 +47,10 @@ from ._exceptions import (
)
from ._debug import breakpoint, post_mortem
from . import msg
from ._root import run, run_daemon, open_root_actor
from ._root import (
run_daemon,
open_root_actor,
)
from ._portal import Portal
from ._runtime import Actor
@ -72,7 +78,6 @@ __all__ = [
'open_root_actor',
'post_mortem',
'query_actor',
'run',
'run_daemon',
'stream',
'to_asyncio',

View File

@ -23,7 +23,9 @@ from functools import partial
import importlib
import logging
import os
from typing import Tuple, Optional, List, Any
from typing import (
Optional,
)
import typing
import warnings
@ -50,7 +52,7 @@ logger = log.get_logger('tractor')
async def open_root_actor(
# defaults are above
arbiter_addr: Optional[Tuple[str, int]] = (
arbiter_addr: Optional[tuple[str, int]] = (
_default_arbiter_host,
_default_arbiter_port,
),
@ -68,8 +70,8 @@ async def open_root_actor(
# internal logging
loglevel: Optional[str] = None,
enable_modules: Optional[List] = None,
rpc_module_paths: Optional[List] = None,
enable_modules: Optional[list] = None,
rpc_module_paths: Optional[list] = None,
) -> typing.Any:
"""Async entry point for ``tractor``.
@ -230,28 +232,35 @@ async def open_root_actor(
logger.runtime("Root actor terminated")
def run(
# target
async_fn: typing.Callable[..., typing.Awaitable],
*args,
def run_daemon(
enable_modules: list[str],
# runtime kwargs
name: Optional[str] = 'root',
arbiter_addr: Tuple[str, int] = (
arbiter_addr: tuple[str, int] = (
_default_arbiter_host,
_default_arbiter_port,
),
start_method: Optional[str] = None,
debug_mode: bool = False,
**kwargs,
**kwargs
) -> Any:
"""Run a trio-actor async function in process.
) -> None:
'''
Spawn daemon actor which will respond to RPC; the main task simply
starts the runtime and then sleeps forever.
This is a very minimal convenience wrapper around starting
a "run-until-cancelled" root actor which can be started with a set
of enabled modules for RPC request handling.
'''
kwargs['enable_modules'] = list(enable_modules)
for path in enable_modules:
importlib.import_module(path)
This is tractor's main entry and the start point for any async actor.
"""
async def _main():
async with open_root_actor(
@ -261,35 +270,6 @@ def run(
debug_mode=debug_mode,
**kwargs,
):
return await trio.sleep_forever()
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)
def run_daemon(
enable_modules: list[str],
**kwargs
) -> None:
'''
Spawn daemon actor which will respond to RPC.
This is a convenience wrapper around
``tractor.run(trio.sleep(float('inf')))`` such that the first actor spawned
is meant to run forever responding to RPC requests.
'''
kwargs['enable_modules'] = list(enable_modules)
for path in enable_modules:
importlib.import_module(path)
return run(partial(trio.sleep, float('inf')), **kwargs)