Polish `to_actor` examples and references

Remaining review threads requested clearer scheduling intent, result
ownership and Portal RPC usage across the migrated examples, plus a
more descriptive concurrent-primes filename.

Explain the relevant example boundaries, fix the transport typo, expand
the local helper signature and rename the live primes example and guide
reference while preserving historical Prompt-IO paths.

Review: PR #481 (goodboy)
https://github.com/goodboy/tractor/pull/481#pullrequestreview-5012942328

(this patch was generated in some part by `opencode` using `gpt-5.6-sol` (`openai`))
wkt/to_actor_subpkg
Gud Boi 2026-08-25 15:20:34 -04:00
parent 98bc642e72
commit 80ce54aeb1
6 changed files with 12 additions and 6 deletions

View File

@ -100,7 +100,7 @@ Semantics worth knowing:
- it blocks until the remote task returns, re-raising any
remote error in the usual boxed form right in the calling
task.
- placement also determines process ownership: ``an=`` spawns and
- lifetime mode also determines process ownership: ``an=`` spawns and
reaps a fresh child in an existing actor nursery, while passing
neither does the same in a private call-scoped nursery (booting
the runtime if needed). ``portal=`` instead runs one linked task
@ -108,7 +108,7 @@ Semantics worth knowing:
the portal's owner remains responsible for its lifetime.
- concurrency composes the plain ``trio`` way: schedule
multiple ``run()`` calls into a local task nursery (see
``examples/parallelism/to_actor_one_shots.py``).
``examples/parallelism/concurrent_toactor_primes.py``).
A reused actor must expose both the target module and the
``to_actor`` context trampoline:

View File

@ -35,8 +35,12 @@ async def main():
for name in ('donny', 'gretchen')
}
async def run_and_print(name: str, other_actor: str):
async def run_and_print(
name: str,
other_actor: str,
) -> None:
print(
# RPC through an existing actor's `Portal`.
await portals[name].run(
say_hello,
other_actor=other_actor,

View File

@ -37,6 +37,8 @@ async def spawn_until(depth=0):
)
)
# Let the background one-shot enter `breakpoint_forever()`
# before its sibling raises and cancellation propagates.
await trio.sleep(0.5)
# rx and propagate error from child
await tractor.to_actor.run(

View File

@ -44,7 +44,7 @@ async def main():
async with (
tractor.open_nursery(
debug_mode=True,
enable_transports=['uds'], # TODO, apss this via osenv?
enable_transports=['uds'], # TODO, pass this via osenv?
loglevel='devx', # XXX, required for test!
) as an,
trio.open_nursery() as tn,

View File

@ -1,5 +1,5 @@
'''
`tractor.to_actor.run()`: one-shot single-task subactor
`tractor.to_actor.run()`: concurrent one-shot prime checks
invocation, the SC-parallelism sibling of
`trio.to_thread.run_sync()` (and `anyio.to_process`).

View File

@ -31,7 +31,7 @@ async def main():
tn.start_soon(burn_cpu)
# run the same func as the lone task in a subactor,
# block on (and collect) its result
# block on and collect its PID as the caller-side result
pid = await tractor.to_actor.run(burn_cpu)
print(f"Collected subproc {pid}")