Write the big boi docs content tree
Replace the ancient `docs/index.rst` (still teaching
`tractor.run()`, `@stream` + arbiters..) with a full ~32 page tree
teaching ONLY the current api (`.wait_for_result()`, registrar
naming, `@context` + `open_context()` as the core model),
- landing: hero example, feature cards + canon links,
- `start/`: install + a 4-example quickstart on-ramp,
- `explain/`: an "SC across processes" essay distilling the essence
per #157's orig ask + a runtime architecture tour,
- `guide/`: 12 task-focused pages incl the flagship multi-process
debugging walkthrough, `Context` + `MsgStream` deep-dives,
cancellation semantics (self-vs-cross cancel rules), discovery,
infected `asyncio`, typed msging + the #126 testing-tips page,
- `api/`: 10 curated autodoc pages (all targets import-verified vs
the reorg'd subpkg tree),
- `project/`: changelog include, ported dev-tips (drops old
`docs/dev_tips.rst`) + roadmap.
Every code block is a `literalinclude` from `examples/`
- zero duplication, all CI-run - w/ `d2` figs floated
into the RHS margin per the 3-col design. Build is green; the 24
remaining warnings all source from lib docstring rst-isms or legacy
`NEWS.rst` content.
Substantially resolves #157 (refine round pending); chips at #175 +
#126.
Prompt-IO: ai/prompt-io/claude/20260611T175152Z_8526985c_prompt_io.md
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-11 19:17:14 +00:00
|
|
|
Trio patterns: ``tractor.trionics``
|
|
|
|
|
===================================
|
|
|
|
|
|
|
|
|
|
Sugary structured concurrency (SC) patterns for plain :mod:`trio`
|
|
|
|
|
code — **no actor runtime required**. These helpers grew out of
|
|
|
|
|
real distributed-system needs in ``tractor`` apps but every one of
|
|
|
|
|
them works in a single-process program too; import via
|
|
|
|
|
``from tractor import trionics``.
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: tractor.trionics
|
|
|
|
|
|
|
|
|
|
Context-manager helpers
|
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
|
|
.. autofunction:: gather_contexts
|
|
|
|
|
|
|
|
|
|
.. autofunction:: maybe_open_context
|
|
|
|
|
|
|
|
|
|
.. autofunction:: maybe_open_nursery
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
:func:`gather_contexts` is "a nursery for async context
|
|
|
|
|
managers": it enters N acms concurrently and yields their
|
|
|
|
|
values in input order. :func:`maybe_open_context` is the
|
|
|
|
|
actor-wide cache/multiplex layer on top — the first task pays
|
|
|
|
|
the acm setup cost, later callers get ``(cache_hit=True, ...)``
|
|
|
|
|
and share the same value until all users exit.
|
|
|
|
|
|
|
|
|
|
Broadcast fan-out
|
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
|
|
.. autofunction:: broadcast_receiver
|
|
|
|
|
|
|
|
|
|
.. autoclass:: BroadcastReceiver
|
|
|
|
|
:members: receive,
|
|
|
|
|
subscribe,
|
|
|
|
|
aclose
|
|
|
|
|
|
|
|
|
|
.. autoexception:: Lagged
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
2026-08-12 04:51:22 +00:00
|
|
|
.. autoexception:: BroadcastReceiveError
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
Write the big boi docs content tree
Replace the ancient `docs/index.rst` (still teaching
`tractor.run()`, `@stream` + arbiters..) with a full ~32 page tree
teaching ONLY the current api (`.wait_for_result()`, registrar
naming, `@context` + `open_context()` as the core model),
- landing: hero example, feature cards + canon links,
- `start/`: install + a 4-example quickstart on-ramp,
- `explain/`: an "SC across processes" essay distilling the essence
per #157's orig ask + a runtime architecture tour,
- `guide/`: 12 task-focused pages incl the flagship multi-process
debugging walkthrough, `Context` + `MsgStream` deep-dives,
cancellation semantics (self-vs-cross cancel rules), discovery,
infected `asyncio`, typed msging + the #126 testing-tips page,
- `api/`: 10 curated autodoc pages (all targets import-verified vs
the reorg'd subpkg tree),
- `project/`: changelog include, ported dev-tips (drops old
`docs/dev_tips.rst`) + roadmap.
Every code block is a `literalinclude` from `examples/`
- zero duplication, all CI-run - w/ `d2` figs floated
into the RHS margin per the 3-col design. Build is green; the 24
remaining warnings all source from lib docstring rst-isms or legacy
`NEWS.rst` content.
Substantially resolves #157 (refine round pending); chips at #175 +
#126.
Prompt-IO: ai/prompt-io/claude/20260611T175152Z_8526985c_prompt_io.md
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-11 19:17:14 +00:00
|
|
|
A single-producer, many-consumer broadcast layer over any
|
|
|
|
|
``trio``-style receive channel: non-lossy for the *fastest*
|
|
|
|
|
consumer while slower consumers raise :class:`Lagged` (a
|
|
|
|
|
:class:`trio.TooSlowError` subtype) once they fall behind the
|
|
|
|
|
internal ring. This is exactly the machinery behind
|
|
|
|
|
:meth:`tractor.MsgStream.subscribe` — see
|
|
|
|
|
``examples/streaming_broadcast_fanout.py``.
|
|
|
|
|
|
2026-08-12 04:51:22 +00:00
|
|
|
If the shared underlying receiver raises an ordinary exception, the
|
|
|
|
|
subscriber which owned that receive gets the original failure.
|
|
|
|
|
Waiting peers drain their retained values and then raise
|
|
|
|
|
:class:`BroadcastReceiveError`, with the original failure available
|
|
|
|
|
as ``__cause__``. Later subscribers observe the same terminal state
|
|
|
|
|
without retrying the failed underlying receiver.
|
|
|
|
|
|
Write the big boi docs content tree
Replace the ancient `docs/index.rst` (still teaching
`tractor.run()`, `@stream` + arbiters..) with a full ~32 page tree
teaching ONLY the current api (`.wait_for_result()`, registrar
naming, `@context` + `open_context()` as the core model),
- landing: hero example, feature cards + canon links,
- `start/`: install + a 4-example quickstart on-ramp,
- `explain/`: an "SC across processes" essay distilling the essence
per #157's orig ask + a runtime architecture tour,
- `guide/`: 12 task-focused pages incl the flagship multi-process
debugging walkthrough, `Context` + `MsgStream` deep-dives,
cancellation semantics (self-vs-cross cancel rules), discovery,
infected `asyncio`, typed msging + the #126 testing-tips page,
- `api/`: 10 curated autodoc pages (all targets import-verified vs
the reorg'd subpkg tree),
- `project/`: changelog include, ported dev-tips (drops old
`docs/dev_tips.rst`) + roadmap.
Every code block is a `literalinclude` from `examples/`
- zero duplication, all CI-run - w/ `d2` figs floated
into the RHS margin per the 3-col design. Build is green; the 24
remaining warnings all source from lib docstring rst-isms or legacy
`NEWS.rst` content.
Substantially resolves #157 (refine round pending); chips at #175 +
#126.
Prompt-IO: ai/prompt-io/claude/20260611T175152Z_8526985c_prompt_io.md
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-06-11 19:17:14 +00:00
|
|
|
ExceptionGroup helpers
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
.. autofunction:: collapse_eg
|
|
|
|
|
|
|
|
|
|
.. autofunction:: maybe_raise_from_masking_exc
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
:func:`collapse_eg` "un-nests" single-exception
|
|
|
|
|
:class:`ExceptionGroup` wrappers from strict-eg ``trio``
|
|
|
|
|
nurseries so your ``except`` clauses match the original error;
|
|
|
|
|
:func:`maybe_raise_from_masking_exc` surfaces real errors that
|
|
|
|
|
would otherwise be masked by :class:`trio.Cancelled` during
|
|
|
|
|
teardown.
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
|
|
:doc:`/api/context` for the IPC-stream consumer of
|
|
|
|
|
:class:`BroadcastReceiver`, :doc:`/guide/streaming` for
|
|
|
|
|
fan-out in a worked pipeline, and the `trio docs`_ for the
|
|
|
|
|
underlying channel and `nursery`_ semantics these helpers
|
|
|
|
|
compose.
|
|
|
|
|
|
|
|
|
|
.. _trio docs: https://trio.readthedocs.io/en/latest/
|
|
|
|
|
.. _nursery: https://trio.readthedocs.io/en/latest/reference-core.html#nurseries-and-spawning
|