Proto a `._state.RuntimeVars` struct
So we can start transition from runtime-vars `dict` to a typed struct for better clarity and wire-ready monitoring potential, as well as better traceability when . Deats, - add a new `RuntimeVars(Struct)` with all fields from `_runtime_vars` dict typed out - include `__setattr__()` with `breakpoint()` for debugging any unexpected mutations. - add `.update()` method for batch-updating compat with `dict`. - keep old `_runtime_vars: dict` in place (we need to port a ton of stuff to adjust..). (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-codetry_to_repl_clobber_aio_task
parent
6a0b8567c4
commit
162d5f76d3
|
|
@ -25,6 +25,7 @@ from contextvars import (
|
|||
from pathlib import Path
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Literal,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
|
@ -32,6 +33,12 @@ from typing import (
|
|||
import platformdirs
|
||||
from trio.lowlevel import current_task
|
||||
|
||||
# from .msg.pretty_struct import Struct
|
||||
from msgspec import (
|
||||
field,
|
||||
Struct,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._runtime import Actor
|
||||
from ._context import Context
|
||||
|
|
@ -48,8 +55,68 @@ _current_actor: Actor|None = None # type: ignore # noqa
|
|||
_last_actor_terminated: Actor|None = None
|
||||
|
||||
# TODO: mk this a `msgspec.Struct`!
|
||||
# -[ ] type out all fields obvi!
|
||||
# -[x] type out all fields obvi!
|
||||
# -[ ] (eventually) mk wire-ready for monitoring?
|
||||
class RuntimeVars(Struct):
|
||||
'''
|
||||
Actor-(and thus process)-global runtime state.
|
||||
|
||||
This struct is relayed from parent to child during sub-actor
|
||||
spawning and is a singleton instance per process.
|
||||
|
||||
Generally contains,
|
||||
- root-actor indicator.
|
||||
- comms-info: addrs for both (public) process/service-discovery
|
||||
and in-tree contact with other actors.
|
||||
- transport-layer IPC protocol server(s) settings.
|
||||
- debug-mode settings for enabling sync breakpointing and any
|
||||
surrounding REPL-fixture hooking.
|
||||
- infected-`asyncio` via guest-mode toggle(s)/cohfig.
|
||||
|
||||
'''
|
||||
_is_root: bool = False # bool
|
||||
_root_mailbox: tuple[str, str|int] = (None, None) # tuple[str|None, str|None]
|
||||
_root_addrs: list[
|
||||
tuple[str, str|int],
|
||||
] = [] # tuple[str|None, str|None]
|
||||
|
||||
# parent->chld ipc protocol caps
|
||||
_enable_tpts: list[TransportProtocolKey] = field(
|
||||
default_factory=lambda: [_def_tpt_proto],
|
||||
)
|
||||
|
||||
# registrar info
|
||||
_registry_addrs: list[tuple] = []
|
||||
|
||||
# `debug_mode: bool` settings
|
||||
_debug_mode: bool = False # bool
|
||||
repl_fixture: bool|Callable = False # |AbstractContextManager[bool]
|
||||
# for `tractor.pause_from_sync()` & `breakpoint()` support
|
||||
use_greenback: bool = False
|
||||
|
||||
# infected-`asyncio`-mode: `trio` running as guest.
|
||||
_is_infected_aio: bool = False
|
||||
|
||||
def __setattr__(
|
||||
self,
|
||||
key,
|
||||
val,
|
||||
) -> None:
|
||||
breakpoint()
|
||||
super().__setattr__(key, val)
|
||||
|
||||
def update(
|
||||
self,
|
||||
from_dict: dict|Struct,
|
||||
) -> None:
|
||||
for attr, val in from_dict.items():
|
||||
setattr(
|
||||
self,
|
||||
attr,
|
||||
val,
|
||||
)
|
||||
|
||||
|
||||
_runtime_vars: dict[str, Any] = {
|
||||
# root of actor-process tree info
|
||||
'_is_root': False, # bool
|
||||
|
|
|
|||
Loading…
Reference in New Issue