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 movie_theatre_question() -> str:
|
2020-02-10 17:08:14 +00:00
|
|
|
"""A question asked in a dark theatre, in a tangent
|
|
|
|
|
(errr, I mean different) process.
|
|
|
|
|
"""
|
|
|
|
|
return 'have you ever seen a 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
|
|
|
async def main() -> None:
|
2020-02-10 17:08:14 +00:00
|
|
|
"""The main ``tractor`` routine.
|
|
|
|
|
"""
|
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
|
|
|
n: tractor.ActorNursery
|
2020-02-10 17:08:14 +00:00
|
|
|
async with tractor.open_nursery() as n:
|
|
|
|
|
|
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
|
|
|
portal: tractor.Portal = await n.start_actor(
|
2020-02-10 17:08:14 +00:00
|
|
|
'frank',
|
|
|
|
|
# enable the actor to run funcs from this current module
|
2021-02-24 23:46:33 +00:00
|
|
|
enable_modules=[__name__],
|
2020-02-10 17:08:14 +00:00
|
|
|
)
|
|
|
|
|
|
2020-12-21 14:09:55 +00:00
|
|
|
print(await portal.run(movie_theatre_question))
|
2020-02-10 17:08:14 +00:00
|
|
|
# call the subactor a 2nd time
|
2020-12-21 14:09:55 +00:00
|
|
|
print(await portal.run(movie_theatre_question))
|
2020-02-10 17:08:14 +00:00
|
|
|
|
|
|
|
|
# the async with will block here indefinitely waiting
|
|
|
|
|
# for our actor "frank" to complete, but since it's an
|
|
|
|
|
# "outlive_main" actor it will never end until cancelled
|
|
|
|
|
await portal.cancel_actor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|