forked from goodboy/tractor
1
0
Fork 0
tractor/tractor
Tyler Goodlet f3ca8608d5 Get msg spec type limiting working with a `RunVar`
Since `contextvars.ContextVar` seems to reset to the default in every
new task, switching to using `trio.lowlevel.RunVar` kinda gets close to
what we'd like where a child scope can override what's in the rent but
ideally without modifying the rent's. I tried `tricycle.TreeVar` as well
but it also seems to reset across (embedded) nurseries in our runtime;
need to try it again bc apparently that's not how it's suppose to work?

NOTE that for now i'm keeping the `.msg.types._ctxvar_MsgCodec` set to
the `msgspec` default (`Any` types) so that the test suite will still
pass until the runtime is ported to the new msg-spec + codec.

Surrounding and in support of all this the `Msg`-set impl deats changed
a bit as well as various stuff in `.msg` sub-mods:

- drop the `.pld` struct types for `Error`, `Start`, `StartAck` since we
  don't really need the `.pld` payload field in those cases since
  they're runtime control msgs for starting RPC tasks and handling
  remote errors; we can just put the fields directly on each msg since
  the user will never want/need to override the `.pld` field type.

- add a couple new runtime msgs and include them in `msg.__spec__`
  and make them NOT inherit from `Msg` since they are runtime-specific
  and thus have no need for `.pld` type constraints:
  - `Aid` the actor-id identity handshake msg.
  - `SpawnSpec`: the spawn data passed from a parent actor down to a
    a child in `Actor._from_parent()` for which we need a shuttle
    protocol msg, so might as well make it a pendatic one ;)

- fix some `Actor.uid` field types that were type-borked on `Error`

- add notes about how we need built-in `debug_mode` msgs in order to
  avoid msg-type errors when using the TTY lock machinery and
  a different `.pld` spec then the default `Any` is in use..
  -> since `devx._debug.lock_tty_for_child()` and it's client side
  `wait_for_parent_stdin_hijack()` use `Context.started('Locked')`
  and `MsgStream.send('pdb_unlock')` string values as their `.pld`
  contents we'd need to either always do a `ipc_pld_spec | str` or
  pre-define some dedicated `Msg` types which get `Union`-ed in
  for this?

- break out `msg.pretty_struct.Struct._sin_props()` into a helper func
  `iter_fields()` since the impl doesn't require a struct instance.

- as mentioned above since `ContextVar` didn't work as anticipated
  I next tried `tricycle.TreeVar` but that too didn't seem to keep
  the `apply_codec()` setting intact across
  `Portal.open_context()`/`Context.open_stream()` (it kept reverting to
  the default `.pld: Any` default setting) so I finalized on
  a trio.lowlevel.RunVar` for now despite it basically being
  a `global`..
  -> will probably come back to test this with `TreeVar` and some hot
  tips i picked up from @mikenerone in the `trio` gitter, which i put in
  comments surrounding proto-code.
2024-04-02 14:02:13 -04:00
..
_testing Add (back) a `tractor._testing` sub-pkg 2024-03-13 09:09:08 -04:00
devx Oof, fix walrus assign causes name-error edge case 2024-03-29 19:15:50 -04:00
experimental Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
msg Get msg spec type limiting working with a `RunVar` 2024-04-02 14:02:13 -04:00
trionics Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
__init__.py Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
_child.py ._child: remove some unused imports.. 2024-01-02 10:24:39 -05:00
_clustering.py Passthrough runtime kwargs from `open_actor_cluster()` 2022-12-11 19:56:08 -05:00
_context.py Add todo-notes for hiding `@acm` frames 2024-03-24 16:49:07 -04:00
_discovery.py More spaceless union type annots 2024-03-11 10:33:06 -04:00
_entry.py `._entry`: use same msg info in start/terminate log 2024-03-05 12:30:34 -05:00
_exceptions.py Change to multi-line-static-`dict` style msgs 2024-03-28 13:08:18 -04:00
_forkserver_override.py Re-license code base for distribution under AGPL 2021-12-14 23:33:27 -05:00
_ipc.py Be mega pedantic with msg-spec building 2024-03-29 19:15:20 -04:00
_mp_fixup_main.py Avoid importing mp for as long as possible 2022-02-17 11:55:26 -05:00
_multiaddr.py Fix doc string "its" typo.. 2023-11-06 15:44:21 -05:00
_portal.py Move `Portal.open_context()` impl to `._context` 2024-03-13 12:09:38 -04:00
_root.py Refine and test `tractor.pause_from_sync()` 2024-03-22 19:58:25 -04:00
_rpc.py Change to multi-line-static-`dict` style msgs 2024-03-28 13:08:18 -04:00
_runtime.py Change all `| None` -> `|None` in `._runtime` 2024-03-25 14:15:36 -04:00
_shm.py Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
_spawn.py Drop now-deprecated deps on modern `trio`/Python 2024-03-13 18:41:24 -04:00
_state.py Add a `._state._runtime_vars['_registry_addrs']` 2024-03-08 15:34:20 -05:00
_streaming.py Re-think, `msgspec`-multi-typed msg dialogs 2024-03-26 17:39:06 -04:00
_supervise.py Drop extra newline from log msg 2024-03-25 15:03:33 -04:00
log.py .log: more multi-line styling 2024-02-20 13:22:44 -05:00
to_asyncio.py Provision for infected-`asyncio` debug mode support 2024-03-25 16:09:32 -04:00