Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.10 and friends #322

Merged
merged 11 commits into from
Sep 16, 2022
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ tasks spawned via multiple RPC calls to an actor can modify


# a per process cache
_actor_cache: Dict[str, bool] = {}
_actor_cache: dict[str, bool] = {}


def ping_endpoints(endpoints: List[str]):
Expand Down
6 changes: 3 additions & 3 deletions examples/parallelism/concurrent_actors_primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"""
from contextlib import asynccontextmanager
from typing import List, Callable
from typing import Callable
import itertools
import math
import time
Expand Down Expand Up @@ -71,8 +71,8 @@ async def worker_pool(workers=4):

async def _map(
worker_func: Callable[[int], bool],
sequence: List[int]
) -> List[bool]:
sequence: list[int]
) -> list[bool]:

# define an async (local) task to collect results from workers
async def send_result(func, value, portal):
Expand Down
16 changes: 16 additions & 0 deletions nooz/322.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Strictly support Python 3.10+, start runtime machinery reorg

Since we want to push forward using the new `match:` syntax for our
internal RPC-msg loops, we officially drop 3.9 support for the next
release which should coincide well with the first release of 3.11.

This patch set also officially removes the ``tractor.run()`` API (which
has been deprecated for some time) as well as starts an initial re-org
of the internal runtime core by:
- renaming ``tractor._actor`` -> ``._runtime``
- moving the ``._runtime.ActorActor._process_messages()`` and
``._async_main()`` to be module level singleton-task-functions since
they are only started once for each connection and actor spawn
respectively; this internal API thus looks more similar to (at the
time of writing) the ``trio``-internals in ``trio._core._run``.
- officially remove ``tractor.run()``, now deprecated for some time.
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

setup(
name="tractor",
version='0.1.0a5', # alpha zone
version='0.1.0a6dev0', # alpha zone
description='structured concurrrent "actors"',
long_description=readme,
license='AGPLv3',
Expand Down Expand Up @@ -55,11 +55,13 @@
'colorlog',
'wrapt',

# serialization
'msgspec',

# pip ref docs on these specs:
# https://pip.pypa.io/en/stable/reference/requirement-specifiers/#examples
# and pep:
# https://peps.python.org/pep-0440/#version-specifiers
'pdbpp <= 0.10.1; python_version < "3.10"',

# windows deps workaround for ``pdbpp``
# https://github.com/pdbpp/pdbpp/issues/498
Expand All @@ -71,9 +73,6 @@
# we need a specific patch on master atm.
'pdbpp @ git+https://github.com/pdbpp/pdbpp@76c4be5#egg=pdbpp ; python_version > "3.9"', # noqa: E501

# serialization
'msgspec >= "0.4.0"'

],
tests_require=['pytest'],
python_requires=">=3.9",
Expand All @@ -94,7 +93,6 @@
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
Expand Down
5 changes: 2 additions & 3 deletions tests/test_advanced_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections import Counter
import itertools
import platform
from typing import Set, Dict, List

import trio
import tractor
Expand All @@ -15,7 +14,7 @@ def is_win():
return platform.system() == 'Windows'


_registry: Dict[str, Set[tractor.ReceiveMsgStream]] = {
_registry: dict[str, set[tractor.ReceiveMsgStream]] = {
'even': set(),
'odd': set(),
}
Expand Down Expand Up @@ -77,7 +76,7 @@ async def subscribe(

async def consumer(

subs: List[str],
subs: list[str],

) -> None:

Expand Down
2 changes: 1 addition & 1 deletion tests/test_context_stream_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def test_one_end_stream_not_opened(overrun_by):

'''
overrunner, buf_size_increase, entrypoint = overrun_by
from tractor._actor import Actor
from tractor._runtime import Actor
buf_size = buf_size_increase + Actor.msg_buffer_size

async def main():
Expand Down
7 changes: 0 additions & 7 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions tests/test_spawning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Spawning basics
"""
from typing import Dict, Tuple, Optional
from typing import Optional

import pytest
import trio
Expand All @@ -14,8 +14,8 @@

async def spawn(
is_arbiter: bool,
data: Dict,
arb_addr: Tuple[str, int],
data: dict,
arb_addr: tuple[str, int],
):
namespaces = [__name__]

Expand Down
6 changes: 3 additions & 3 deletions tests/test_task_broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import partial
from itertools import cycle
import time
from typing import Optional, List, Tuple
from typing import Optional

import pytest
import trio
Expand Down Expand Up @@ -62,8 +62,8 @@ async def ensure_sequence(
@asynccontextmanager
async def open_sequence_streamer(

sequence: List[int],
arb_addr: Tuple[str, int],
sequence: list[int],
arb_addr: tuple[str, int],
start_method: str,

) -> tractor.MsgStream:
Expand Down
13 changes: 10 additions & 3 deletions tractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@
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,
ContextCancelled,
)
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


__all__ = [
'Actor',
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing purely for type annotations.

'Channel',
'Context',
'ContextCancelled',
Expand All @@ -70,7 +78,6 @@
'open_root_actor',
'post_mortem',
'query_actor',
'run',
'run_daemon',
'stream',
'to_asyncio',
Expand Down
2 changes: 1 addition & 1 deletion tractor/_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from ast import literal_eval

from ._actor import Actor
from ._runtime import Actor
from ._entry import _trio_main


Expand Down
15 changes: 7 additions & 8 deletions tractor/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from functools import partial
from contextlib import asynccontextmanager as acm
from typing import (
Tuple,
Optional,
Callable,
AsyncIterator,
Expand Down Expand Up @@ -74,7 +73,7 @@ class Lock:
local_task_in_debug: Optional[str] = None

# actor tree-wide actor uid that supposedly has the tty lock
global_actor_in_debug: Optional[Tuple[str, str]] = None
global_actor_in_debug: Optional[tuple[str, str]] = None

local_pdb_complete: Optional[trio.Event] = None
no_remote_has_tty: Optional[trio.Event] = None
Expand Down Expand Up @@ -172,7 +171,7 @@ def set_quit(self):

@acm
async def _acquire_debug_lock_from_root_task(
uid: Tuple[str, str]
uid: tuple[str, str]

) -> AsyncIterator[trio.StrictFIFOLock]:
'''
Expand Down Expand Up @@ -252,7 +251,7 @@ async def _acquire_debug_lock_from_root_task(
async def lock_tty_for_child(

ctx: tractor.Context,
subactor_uid: Tuple[str, str]
subactor_uid: tuple[str, str]

) -> str:
'''
Expand Down Expand Up @@ -302,7 +301,7 @@ async def lock_tty_for_child(


async def wait_for_parent_stdin_hijack(
actor_uid: Tuple[str, str],
actor_uid: tuple[str, str],
task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED
):
'''
Expand Down Expand Up @@ -643,7 +642,7 @@ def do_cancel():


def _set_trace(
actor: Optional[tractor._actor.Actor] = None,
actor: Optional[tractor.Actor] = None,
pdb: Optional[MultiActorPdb] = None,
):
__tracebackhide__ = True
Expand Down Expand Up @@ -676,7 +675,7 @@ def _set_trace(


def _post_mortem(
actor: tractor._actor.Actor,
actor: tractor.Actor,
pdb: MultiActorPdb,

) -> None:
Expand Down Expand Up @@ -732,7 +731,7 @@ async def _maybe_enter_pm(err):

@acm
async def acquire_debug_lock(
subactor_uid: Tuple[str, str],
subactor_uid: tuple[str, str],
) -> AsyncGenerator[None, tuple]:
'''
Grab root's debug lock on entry, release on exit.
Expand Down
10 changes: 7 additions & 3 deletions tractor/_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
Actor discovery API.

"""
from typing import Tuple, Optional, Union, AsyncGenerator
from typing import (
Optional,
Union,
AsyncGenerator,
)
from contextlib import asynccontextmanager as acm

from ._ipc import _connect_chan, Channel
Expand Down Expand Up @@ -104,7 +108,7 @@ async def query_actor(
@acm
async def find_actor(
name: str,
arbiter_sockaddr: Tuple[str, int] = None
arbiter_sockaddr: tuple[str, int] = None

) -> AsyncGenerator[Optional[Portal], None]:
'''
Expand All @@ -130,7 +134,7 @@ async def find_actor(
@acm
async def wait_for_actor(
name: str,
arbiter_sockaddr: Tuple[str, int] = None
arbiter_sockaddr: tuple[str, int] = None
) -> AsyncGenerator[Portal, None]:
"""Wait on an actor to register with the arbiter.

Expand Down
20 changes: 11 additions & 9 deletions tractor/_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

"""
from functools import partial
from typing import Tuple, Any
import signal
from typing import Any

import trio # type: ignore

from .log import get_console_log, get_logger
from . import _state
from .to_asyncio import run_as_asyncio_guest
from ._runtime import async_main, Actor


log = get_logger(__name__)
Expand All @@ -35,10 +35,10 @@
def _mp_main(

actor: 'Actor', # type: ignore
accept_addr: Tuple[str, int],
forkserver_info: Tuple[Any, Any, Any, Any, Any],
accept_addr: tuple[str, int],
forkserver_info: tuple[Any, Any, Any, Any, Any],
start_method: str,
parent_addr: Tuple[str, int] = None,
parent_addr: tuple[str, int] = None,
infect_asyncio: bool = False,

) -> None:
Expand All @@ -63,7 +63,8 @@ def _mp_main(

log.debug(f"parent_addr is {parent_addr}")
trio_main = partial(
actor._async_main,
async_main,
actor,
accept_addr,
parent_addr=parent_addr
)
Expand All @@ -82,9 +83,9 @@ def _mp_main(

def _trio_main(

actor: 'Actor', # type: ignore
actor: Actor, # type: ignore
*,
parent_addr: Tuple[str, int] = None,
parent_addr: tuple[str, int] = None,
infect_asyncio: bool = False,

) -> None:
Expand All @@ -106,7 +107,8 @@ def _trio_main(

log.debug(f"parent_addr is {parent_addr}")
trio_main = partial(
actor._async_main,
async_main,
actor,
parent_addr=parent_addr
)

Expand Down
Loading