2021-02-24 18:39:14 +00:00
|
|
|
import trio
|
2020-02-10 17:08:14 +00:00
|
|
|
import tractor
|
|
|
|
|
|
|
|
|
|
|
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 assert_err() -> None:
|
2026-08-29 22:58:43 +00:00
|
|
|
'''
|
|
|
|
|
Raise an assertion error in the current actor.
|
|
|
|
|
|
|
|
|
|
'''
|
2020-02-10 17:08:14 +00:00
|
|
|
assert 0
|
|
|
|
|
|
|
|
|
|
|
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:
|
2026-08-29 22:58:43 +00:00
|
|
|
'''
|
|
|
|
|
Propagate a failing one-shot task from a subactor.
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
an: tractor.ActorNursery
|
2026-08-20 03:29:02 +00:00
|
|
|
async with tractor.open_nursery() as an:
|
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
|
|
|
real_actors: list[tractor.Portal] = []
|
2026-08-29 22:58:43 +00:00
|
|
|
i: int
|
2020-02-10 17:08:14 +00:00
|
|
|
for i in range(3):
|
2026-08-29 22:58:43 +00:00
|
|
|
real_actors.append(
|
|
|
|
|
await an.start_actor(
|
|
|
|
|
f'actor_{i}',
|
|
|
|
|
enable_modules=[__name__],
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-02-10 17:08:14 +00:00
|
|
|
|
2026-08-20 03:29:02 +00:00
|
|
|
# run one one-shot task actor that will fail immediately;
|
|
|
|
|
# its error raises right here in the caller's task..
|
|
|
|
|
await tractor.to_actor.run(assert_err, an=an)
|
2020-02-10 17:08:14 +00:00
|
|
|
|
2026-08-20 03:29:02 +00:00
|
|
|
# ..as a ``RemoteActorError`` containing an ``AssertionError``
|
|
|
|
|
# and all the other actors have been cancelled
|
2020-02-10 17:08:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
try:
|
|
|
|
|
# also raises
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|
2020-02-10 17:08:14 +00:00
|
|
|
except tractor.RemoteActorError:
|
2026-08-29 22:58:43 +00:00
|
|
|
print('Look Maa that actor failed hard, hehhh!')
|