2021-08-03 01:49:15 +00:00
|
|
|
from typing import AsyncIterator
|
2020-02-09 07:01:39 +00:00
|
|
|
from itertools import repeat
|
2021-08-03 01:49:15 +00:00
|
|
|
|
2020-02-09 07:01:39 +00:00
|
|
|
import trio
|
|
|
|
|
import tractor
|
|
|
|
|
|
|
|
|
|
|
2021-08-03 01:49:15 +00:00
|
|
|
async def stream_forever() -> AsyncIterator[int]:
|
2020-02-09 07:01:39 +00:00
|
|
|
|
|
|
|
|
for i in repeat("I can see these little future bubble things"):
|
2021-08-03 01:49:15 +00:00
|
|
|
# each yielded value is sent over the ``Channel`` to the parent actor
|
2020-02-09 07:01:39 +00:00
|
|
|
yield i
|
|
|
|
|
await trio.sleep(0.01)
|
|
|
|
|
|
|
|
|
|
|
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-02-24 18:39:14 +00:00
|
|
|
|
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
|
2021-08-03 01:49:15 +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(
|
2021-08-03 01:49:15 +00:00
|
|
|
'donny',
|
|
|
|
|
enable_modules=[__name__],
|
|
|
|
|
)
|
2021-02-24 18:39:14 +00:00
|
|
|
|
2021-08-03 01:49:15 +00:00
|
|
|
# this async for loop streams values from the above
|
|
|
|
|
# async generator running in a separate process
|
|
|
|
|
async with portal.open_stream_from(stream_forever) as stream:
|
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
|
|
|
count: int = 0
|
2021-08-03 01:49:15 +00:00
|
|
|
async for letter in stream:
|
|
|
|
|
print(letter)
|
|
|
|
|
count += 1
|
2021-02-24 18:39:14 +00:00
|
|
|
|
2021-08-03 01:49:15 +00:00
|
|
|
if count > 50:
|
|
|
|
|
break
|
2020-02-09 07:01:39 +00:00
|
|
|
|
2021-08-03 01:49:15 +00:00
|
|
|
print('stream terminated')
|
2020-02-09 07:01:39 +00:00
|
|
|
|
2021-08-03 01:49:15 +00:00
|
|
|
await portal.cancel_actor()
|
2020-02-09 07:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|