2021-11-02 19:37:36 +00:00
|
|
|
|
|
|
|
|
import trio
|
|
|
|
|
import tractor
|
|
|
|
|
|
|
|
|
|
|
2025-03-03 22:55:07 +00:00
|
|
|
async def sleepy_jane() -> None:
|
|
|
|
|
uid: tuple = tractor.current_actor().uid
|
2021-11-02 19:37:36 +00:00
|
|
|
print(f'Yo i am actor {uid}')
|
|
|
|
|
await trio.sleep_forever()
|
|
|
|
|
|
|
|
|
|
|
Type the docs-visible `examples/` scripts
Type the runtime objects (`ActorNursery`, `Portal`, `Context`,
`trio.Nursery`) + fn signatures across the 16 highest-visibility,
`literalinclude`-d `examples/` scripts, matching the front-page
`we_are_processes.py` style — so the rendered guides show typed
usage throughout, not just on the landing snippet.
Spans the 3 quickstart-backing scripts + `single_func`,
`remote_error_propagation`, `multiple_streams_one_portal`,
`quick_cluster`, `service_discovery`, `service_daemon_discovery`,
`asynchronous_generators`, `nested_actor_tree`,
`concurrent_actors_primes`, `streaming_broadcast_fanout`,
`rpc_bidir_streaming`, `infected_asyncio_echo_server`,
`typed_payloads`.
Annotation-only (no renames/logic changes); each runs green and the
docs build stays warning-free. Part of the examples-typing bullet
in #472.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-07-02 16:32:49 +00:00
|
|
|
async def main() -> None:
|
2021-11-02 19:37:36 +00:00
|
|
|
'''
|
2025-03-03 22:55:07 +00:00
|
|
|
Spawn a flat actor cluster, with one process per detected core.
|
2021-11-02 19:37:36 +00:00
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
portal_map: dict[str, tractor.Portal]
|
Type the docs-visible `examples/` scripts
Type the runtime objects (`ActorNursery`, `Portal`, `Context`,
`trio.Nursery`) + fn signatures across the 16 highest-visibility,
`literalinclude`-d `examples/` scripts, matching the front-page
`we_are_processes.py` style — so the rendered guides show typed
usage throughout, not just on the landing snippet.
Spans the 3 quickstart-backing scripts + `single_func`,
`remote_error_propagation`, `multiple_streams_one_portal`,
`quick_cluster`, `service_discovery`, `service_daemon_discovery`,
`asynchronous_generators`, `nested_actor_tree`,
`concurrent_actors_primes`, `streaming_broadcast_fanout`,
`rpc_bidir_streaming`, `infected_asyncio_echo_server`,
`typed_payloads`.
Annotation-only (no renames/logic changes); each runs green and the
docs build stays warning-free. Part of the examples-typing bullet
in #472.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-07-02 16:32:49 +00:00
|
|
|
tn: trio.Nursery
|
2021-11-02 19:37:36 +00:00
|
|
|
|
|
|
|
|
# look at this hip new syntax!
|
|
|
|
|
async with (
|
|
|
|
|
|
|
|
|
|
tractor.open_actor_cluster(
|
|
|
|
|
modules=[__name__]
|
|
|
|
|
) as portal_map,
|
|
|
|
|
|
2025-08-18 16:03:10 +00:00
|
|
|
tractor.trionics.collapse_eg(),
|
|
|
|
|
trio.open_nursery() as tn,
|
2021-11-02 19:37:36 +00:00
|
|
|
):
|
|
|
|
|
|
|
|
|
|
for (name, portal) in portal_map.items():
|
2025-03-03 22:55:07 +00:00
|
|
|
tn.start_soon(
|
|
|
|
|
portal.run,
|
|
|
|
|
sleepy_jane,
|
|
|
|
|
)
|
2021-11-02 19:37:36 +00:00
|
|
|
|
|
|
|
|
await trio.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
# kill the cluster with a cancel
|
|
|
|
|
raise KeyboardInterrupt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
try:
|
|
|
|
|
trio.run(main)
|
|
|
|
|
except KeyboardInterrupt:
|
2025-03-03 22:55:07 +00:00
|
|
|
print('trio cancelled by KBI')
|