3.4 KiB
Raw AI output (diff-ref mode)
All generated code is committed on the wkt/to_actor_subpkg branch; per diff-ref mode each file’s verbatim content is reachable via the pointers below rather than duplicated here.
Generated files
git diff main..wkt/to_actor_subpkg -- tractor/to_actor/__init__.py
New subpackage init: module docstring establishing the trio.to_thread/anyio.to_process “run it over there” parlance for actors, plus the single public re-export run as run from ._api.
git diff main..wkt/to_actor_subpkg -- tractor/to_actor/_api.py
The one-shot invocation impl, composed entirely from the lower level daemon-spawn + portal primitives as prescribed by issue #477:
_validate_one_shot_fn(): thePortal.run()non-streaming-async-fn constraint checked up-front, before any subactor is spawned._invoke_in_subactor():an.start_actor()->Portal.run()-> always-reap viaPortal.cancel_actor()in afinally(the cancel req’s bounded wait is internally shielded so the reap also runs under caller-scope cancellation).run(): the public API. Placement options:portal=(reuse a running actor, no spawn/reap),an=(spawn from a caller-managed nursery), or neither (privateopen_nursery()scoped to the call, implicitly booting the runtime when needed, tunable via pass-throughruntime_kwargs). Spawn opts mirrorActorNursery.start_actor();**fn_kwargsare relayed to the remote task. Errors raise in the caller’s task as boxedRemoteActorErrors.runtime_kwargsalongside any placement opt is a hardValueError, never silently ignored.
git diff main..wkt/to_actor_subpkg -- tractor/__init__.py
Top-level from . import to_actor as to_actor re-export.
git diff main..wkt/to_actor_subpkg -- tractor/runtime/_supervise.py
Comment/docstring-only: the run_in_actor() deprecation TODO now points at the implemented .to_actor.run() successor (checkbox ticked) and the method docstring gains a NOTE steering users to the new API; remaining TODO items are the DeprecationWarning emission + in-repo usage migration.
git diff main..wkt/to_actor_subpkg -- tests/test_to_actor.py
11-test suite: private-nursery one-shot, implicit runtime boot via runtime_kwargs, remote-error relay to the caller’s task (bare + caller-managed nursery), caller-nursery spawn, portal reuse w/o implicit reap, the concurrent worker-pool-ish pattern (local trio nursery x shared an), and the four validation rejections (sync fn, async-gen fn, portal+an combo, runtime_kwargs+placement combo).
git diff main..wkt/to_actor_subpkg -- examples/parallelism/to_actor_one_shots.py
Runnable example (auto-collected by test_docs_examples.py): the fully-implicit one-shot plus the concurrent worker-pool-ish prime-check pattern against a shared caller-managed actor-nursery.
Test runs (verbatim)
tests/test_to_actor.py .......... [100%]
============= 10 passed in 4.29s =============
Regression subset for touched modules (test_local.py test_rpc.py test_spawning.py test_cancellation.py):
38 passed, 1 xfailed, 24 warnings in 80.71s (0:01:20)
(warnings are pre-existing stdlib os.fork() DeprecationWarnings from the mp spawn backends, not introduced by this change)