Extract `_actor_child_main()` as shared child entry
Pull the `_child.py` `__main__` block body out into
a callable `_actor_child_main()` so alternate spawn
backends can bootstrap a subactor without going
through the CLI entrypoint.
Deats,
- new `_actor_child_main(uid, loglevel, parent_addr,
infect_asyncio, spawn_method='trio')` holds the
full child-side runtime startup previously inlined
under `if __name__ == '__main__':`
- `__main__` block reduces to arg-parsing + a call
into the new func
- add `"subint"` to the `_runtime.py` spawn-method
check so a child accepts `SpawnSpec` from that
(future) backend; inert str-compare w/o it
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
(cherry picked from commit b8f243e98d)
(factored: kept only the `_child.py`/`_runtime.py` entry-extraction parts of
"Impl min-viable `subint` spawn backend (B.2)"; dropped
tractor/spawn/_subint.py + subint prompt-io logs)
wkt/tooling_enhancements_from_mtf_spawner
parent
4052c5b562
commit
8726323170
|
|
@ -15,16 +15,23 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
This is the "bootloader" for actors started using the native trio backend.
|
||||
The "bootloader" for sub-actors spawned via the native `trio`
|
||||
backend (the default `python -m tractor._child` CLI entry) and
|
||||
the in-process `subint` backend (`tractor.spawn._subint`).
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
|
||||
from ast import literal_eval
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from .runtime._runtime import Actor
|
||||
from .spawn._entry import _trio_main
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .discovery._addr import UnwrappedAddress
|
||||
from .spawn._spawn import SpawnMethodKey
|
||||
|
||||
|
||||
def parse_uid(arg):
|
||||
name, uuid = literal_eval(arg) # ensure 2 elements
|
||||
|
|
@ -39,6 +46,36 @@ def parse_ipaddr(arg):
|
|||
return arg
|
||||
|
||||
|
||||
def _actor_child_main(
|
||||
uid: tuple[str, str],
|
||||
loglevel: str | None,
|
||||
parent_addr: UnwrappedAddress | None,
|
||||
infect_asyncio: bool,
|
||||
spawn_method: SpawnMethodKey = 'trio',
|
||||
|
||||
) -> None:
|
||||
'''
|
||||
Construct the child `Actor` and dispatch to `_trio_main()`.
|
||||
|
||||
Shared entry shape used by both the `python -m tractor._child`
|
||||
CLI (trio/mp subproc backends) and the `subint` backend, which
|
||||
invokes this from inside a fresh `concurrent.interpreters`
|
||||
sub-interpreter via `Interpreter.call()`.
|
||||
|
||||
'''
|
||||
subactor = Actor(
|
||||
name=uid[0],
|
||||
uuid=uid[1],
|
||||
loglevel=loglevel,
|
||||
spawn_method=spawn_method,
|
||||
)
|
||||
_trio_main(
|
||||
subactor,
|
||||
parent_addr=parent_addr,
|
||||
infect_asyncio=infect_asyncio,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
__tracebackhide__: bool = True
|
||||
|
||||
|
|
@ -49,15 +86,10 @@ if __name__ == "__main__":
|
|||
parser.add_argument("--asyncio", action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
subactor = Actor(
|
||||
name=args.uid[0],
|
||||
uuid=args.uid[1],
|
||||
_actor_child_main(
|
||||
uid=args.uid,
|
||||
loglevel=args.loglevel,
|
||||
spawn_method="trio"
|
||||
)
|
||||
|
||||
_trio_main(
|
||||
subactor,
|
||||
parent_addr=args.parent_addr,
|
||||
infect_asyncio=args.asyncio,
|
||||
spawn_method='trio',
|
||||
)
|
||||
|
|
|
|||
|
|
@ -870,7 +870,7 @@ class Actor:
|
|||
|
||||
accept_addrs: list[UnwrappedAddress]|None = None
|
||||
|
||||
if self._spawn_method == "trio":
|
||||
if self._spawn_method in ("trio", "subint"):
|
||||
|
||||
# Receive post-spawn runtime state from our parent.
|
||||
spawnspec: msgtypes.SpawnSpec = await chan.recv()
|
||||
|
|
|
|||
Loading…
Reference in New Issue