From 71de56b09a73dcaf14d5222f49bc68bedcfcb4c9 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 13 Mar 2024 18:41:24 -0400 Subject: [PATCH] Drop now-deprecated deps on modern `trio`/Python - `trio_typing` is nearly obsolete since `trio >= 0.23` - `exceptiongroup` is built-in to python 3.11 - `async_generator` primitives have lived in `contextlib` for quite a while! --- examples/debugging/debug_mode_hang.py | 9 +++++++++ .../parallelism/concurrent_actors_primes.py | 8 +++++--- examples/rpc_bidir_streaming.py | 2 +- setup.py | 7 ++++--- tests/test_cancellation.py | 4 ---- tests/test_child_manages_service_nursery.py | 6 ++++-- tests/test_infected_asyncio.py | 1 - tests/test_runtime.py | 3 ++- tests/test_trioisms.py | 2 +- tractor/__init__.py | 2 -- tractor/_exceptions.py | 11 +++++------ tractor/_root.py | 3 ++- tractor/_rpc.py | 6 +----- tractor/_runtime.py | 2 -- tractor/_shm.py | 2 +- tractor/_spawn.py | 17 ++++++++--------- tractor/_supervise.py | 1 - tractor/experimental/_pubsub.py | 2 +- tractor/trionics/_mngrs.py | 7 +++---- 19 files changed, 47 insertions(+), 48 deletions(-) create mode 100644 examples/debugging/debug_mode_hang.py diff --git a/examples/debugging/debug_mode_hang.py b/examples/debugging/debug_mode_hang.py new file mode 100644 index 0000000..a81890e --- /dev/null +++ b/examples/debugging/debug_mode_hang.py @@ -0,0 +1,9 @@ +''' +Reproduce a bug where enabling debug mode for a sub-actor actually causes +a hang on teardown... + +''' +import asyncio + +import trio +import tractor diff --git a/examples/parallelism/concurrent_actors_primes.py b/examples/parallelism/concurrent_actors_primes.py index feaaca7..748861e 100644 --- a/examples/parallelism/concurrent_actors_primes.py +++ b/examples/parallelism/concurrent_actors_primes.py @@ -8,7 +8,10 @@ This uses no extra threads, fancy semaphores or futures; all we need is ``tractor``'s channels. """ -from contextlib import asynccontextmanager +from contextlib import ( + asynccontextmanager as acm, + aclosing, +) from typing import Callable import itertools import math @@ -16,7 +19,6 @@ import time import tractor import trio -from async_generator import aclosing PRIMES = [ @@ -44,7 +46,7 @@ async def is_prime(n): return True -@asynccontextmanager +@acm async def worker_pool(workers=4): """Though it's a trivial special case for ``tractor``, the well known "worker pool" seems to be the defacto "but, I want this diff --git a/examples/rpc_bidir_streaming.py b/examples/rpc_bidir_streaming.py index 7320081..c961bf2 100644 --- a/examples/rpc_bidir_streaming.py +++ b/examples/rpc_bidir_streaming.py @@ -13,7 +13,7 @@ async def simple_rpc( ''' # signal to parent that we're up much like - # ``trio_typing.TaskStatus.started()`` + # ``trio.TaskStatus.started()`` await ctx.started(data + 1) async with ctx.open_stream() as stream: diff --git a/setup.py b/setup.py index 7f6d8f5..50ee92e 100755 --- a/setup.py +++ b/setup.py @@ -47,9 +47,10 @@ setup( # proper range spec: # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#id5 'trio >= 0.24', - 'async_generator', - 'trio_typing', - 'exceptiongroup', + + # 'async_generator', # in stdlib mostly! + # 'trio_typing', # trio==0.23.0 has type hints! + # 'exceptiongroup', # in stdlib as of 3.11! # tooling 'stackscope', diff --git a/tests/test_cancellation.py b/tests/test_cancellation.py index 5b589f6..b8c14af 100644 --- a/tests/test_cancellation.py +++ b/tests/test_cancellation.py @@ -8,10 +8,6 @@ import platform import time from itertools import repeat -from exceptiongroup import ( - BaseExceptionGroup, - ExceptionGroup, -) import pytest import trio import tractor diff --git a/tests/test_child_manages_service_nursery.py b/tests/test_child_manages_service_nursery.py index 228d6ad..350f939 100644 --- a/tests/test_child_manages_service_nursery.py +++ b/tests/test_child_manages_service_nursery.py @@ -6,13 +6,15 @@ sub-sub-actor daemons. ''' from typing import Optional import asyncio -from contextlib import asynccontextmanager as acm +from contextlib import ( + asynccontextmanager as acm, + aclosing, +) import pytest import trio import tractor from tractor import RemoteActorError -from async_generator import aclosing async def aio_streamer( diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index a3f96ee..568708a 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -8,7 +8,6 @@ import builtins import itertools import importlib -from exceptiongroup import BaseExceptionGroup import pytest import trio import tractor diff --git a/tests/test_runtime.py b/tests/test_runtime.py index 3755af1..55553dd 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -64,7 +64,8 @@ async def test_lifetime_stack_wipes_tmpfile( except ( tractor.RemoteActorError, - tractor.BaseExceptionGroup, + # tractor.BaseExceptionGroup, + BaseExceptionGroup, ): pass diff --git a/tests/test_trioisms.py b/tests/test_trioisms.py index 5b19f50..27dc6c3 100644 --- a/tests/test_trioisms.py +++ b/tests/test_trioisms.py @@ -5,7 +5,7 @@ want to see changed. ''' import pytest import trio -from trio_typing import TaskStatus +from trio import TaskStatus @pytest.mark.parametrize( diff --git a/tractor/__init__.py b/tractor/__init__.py index 01d00ec..c7d21c9 100644 --- a/tractor/__init__.py +++ b/tractor/__init__.py @@ -18,8 +18,6 @@ tractor: structured concurrent ``trio``-"actors". """ -from exceptiongroup import BaseExceptionGroup as BaseExceptionGroup - from ._clustering import ( open_actor_cluster as open_actor_cluster, ) diff --git a/tractor/_exceptions.py b/tractor/_exceptions.py index 259a28a..344f0c3 100644 --- a/tractor/_exceptions.py +++ b/tractor/_exceptions.py @@ -30,11 +30,10 @@ from typing import ( import textwrap import traceback -import exceptiongroup as eg import trio -from ._state import current_actor -from .log import get_logger +from tractor._state import current_actor +from tractor.log import get_logger if TYPE_CHECKING: from ._context import Context @@ -373,7 +372,6 @@ def unpack_error( for ns in [ builtins, _this_mod, - eg, trio, ]: if suberror_type := getattr( @@ -396,12 +394,13 @@ def unpack_error( def is_multi_cancelled(exc: BaseException) -> bool: ''' - Predicate to determine if a possible ``eg.BaseExceptionGroup`` contains + Predicate to determine if a possible ``BaseExceptionGroup`` contains only ``trio.Cancelled`` sub-exceptions (and is likely the result of cancelling a collection of subtasks. ''' - if isinstance(exc, eg.BaseExceptionGroup): + # if isinstance(exc, eg.BaseExceptionGroup): + if isinstance(exc, BaseExceptionGroup): return exc.subgroup( lambda exc: isinstance(exc, trio.Cancelled) ) is not None diff --git a/tractor/_root.py b/tractor/_root.py index 6ee78b9..5445191 100644 --- a/tractor/_root.py +++ b/tractor/_root.py @@ -28,12 +28,13 @@ import os import warnings -from exceptiongroup import BaseExceptionGroup import trio from ._runtime import ( Actor, Arbiter, + # TODO: rename and make a non-actor subtype? + # Arbiter as Registry, async_main, ) from .devx import _debug diff --git a/tractor/_rpc.py b/tractor/_rpc.py index 54a60be..6bdc0c6 100644 --- a/tractor/_rpc.py +++ b/tractor/_rpc.py @@ -21,6 +21,7 @@ Remote (task) Procedure Call (scheduling) with SC transitive semantics. from __future__ import annotations from contextlib import ( asynccontextmanager as acm, + aclosing, ) from functools import partial import inspect @@ -34,17 +35,12 @@ from typing import ( ) import warnings -from async_generator import aclosing -from exceptiongroup import BaseExceptionGroup import trio from trio import ( CancelScope, Nursery, TaskStatus, ) -# from trio_typing import ( -# TaskStatus, -# ) from .msg import NamespacePath from ._ipc import Channel diff --git a/tractor/_runtime.py b/tractor/_runtime.py index 838c648..ff929c0 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -61,8 +61,6 @@ import warnings import trio from trio import ( CancelScope, -) -from trio_typing import ( Nursery, TaskStatus, ) diff --git a/tractor/_shm.py b/tractor/_shm.py index f829510..da6d8dd 100644 --- a/tractor/_shm.py +++ b/tractor/_shm.py @@ -46,7 +46,7 @@ if _USE_POSIX: try: import numpy as np from numpy.lib import recfunctions as rfn - import nptyping + # import nptyping except ImportError: pass diff --git a/tractor/_spawn.py b/tractor/_spawn.py index e23d70f..741a2f8 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -31,25 +31,24 @@ from typing import ( TYPE_CHECKING, ) -from exceptiongroup import BaseExceptionGroup import trio -from trio_typing import TaskStatus +from trio import TaskStatus -from .devx import ( +from tractor.devx import ( maybe_wait_for_debugger, acquire_debug_lock, ) -from ._state import ( +from tractor._state import ( current_actor, is_main_process, is_root_process, debug_mode, ) -from .log import get_logger -from ._portal import Portal -from ._runtime import Actor -from ._entry import _mp_main -from ._exceptions import ActorFailure +from tractor.log import get_logger +from tractor._portal import Portal +from tractor._runtime import Actor +from tractor._entry import _mp_main +from tractor._exceptions import ActorFailure if TYPE_CHECKING: diff --git a/tractor/_supervise.py b/tractor/_supervise.py index 50f0d5e..733dd53 100644 --- a/tractor/_supervise.py +++ b/tractor/_supervise.py @@ -26,7 +26,6 @@ from typing import TYPE_CHECKING import typing import warnings -from exceptiongroup import BaseExceptionGroup import trio from .devx._debug import maybe_wait_for_debugger diff --git a/tractor/experimental/_pubsub.py b/tractor/experimental/_pubsub.py index 89f286d..b894ed4 100644 --- a/tractor/experimental/_pubsub.py +++ b/tractor/experimental/_pubsub.py @@ -31,7 +31,7 @@ from typing import ( Callable, ) from functools import partial -from async_generator import aclosing +from contextlib import aclosing import trio import wrapt diff --git a/tractor/trionics/_mngrs.py b/tractor/trionics/_mngrs.py index 1c079cd..f57be0a 100644 --- a/tractor/trionics/_mngrs.py +++ b/tractor/trionics/_mngrs.py @@ -33,10 +33,9 @@ from typing import ( ) import trio -from trio_typing import TaskStatus -from .._state import current_actor -from ..log import get_logger +from tractor._state import current_actor +from tractor.log import get_logger log = get_logger(__name__) @@ -184,7 +183,7 @@ class _Cache: cls, mng, ctx_key: tuple, - task_status: TaskStatus[T] = trio.TASK_STATUS_IGNORED, + task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED, ) -> None: async with mng as value: