Bluesky documents¶
These names are imported from sharedbox.bluebox, which needs the
bluebox extra:
| Name | What it does |
|---|---|
DocumentSender |
sends the documents of bluesky runs on a channel; subscribe it to a RunEngine |
DocumentReceiver |
receives a channel's documents in the order they were sent, in mode lossless, lossy or latest |
ReceiverReleasedError |
a receiver lost documents and was closed |
LateJoinError |
the run under way is too large for a receiver to join it |
DocumentSender
¶
DocumentSender(name: str, control: SharedStream[ControlItem, Any], box: ChannelState, *, event_capacity: int, max_readers: int, string_capacity: int, page_rows: int, control_timeout: float, event_timeout: float | None, on_full: Literal['wait', 'release'])
Sends bluesky documents on a channel that receivers in any process attach to.
Make one with create, not
the constructor. Call it with each document's name and the document, as
a RunEngine callback is called. Events and event pages go to an event stream per
descriptor, every other document to the channel's control stream.
Closing the sender ends the channel: receivers deliver what they hold,
then raise EndOfStream.
create
classmethod
¶
create(name: str, *, event_capacity: int = 8, max_readers: int = 8, control_capacity: int = 64, string_capacity: int = 256, page_rows: int = 16, control_timeout: float = 5.0, event_timeout: float | None = None, on_full: Literal['wait', 'release'] = 'wait') -> Self
Create the channel name.
A channel whose creator has exited is removed first. The run's start and descriptors are kept for receivers that attach mid-run while their CBOR takes at most 1 MiB; a larger run refuses such receivers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_capacity
|
int
|
Items each event stream holds. |
8
|
max_readers
|
int
|
Readers the control stream and each event stream take. A lossless receiver takes one place on the control stream, a lossy or latest receiver two, so 8 lets 8 lossless or 4 lossy receivers attach at once. |
8
|
control_capacity
|
int
|
Parts of 16 KiB the control stream holds. |
64
|
string_capacity
|
int
|
Most bytes of UTF-8 in a string of an event. |
256
|
page_rows
|
int
|
Most rows of an event page one item of an event stream holds. |
16
|
control_timeout
|
float
|
Seconds a control document waits for a receiver that stopped reading before the sender releases it. It also bounds the wait for the lossless receivers to open the event stream of a descriptor, once a descriptor's events no longer fit in its stream and at the stop: the sender waits for a receiver process until that long passes without the process reading a control document. The limit applies per process, so once one receiver misses it, no receiver of that process is waited for again in the run. |
5.0
|
event_timeout
|
float | None
|
Seconds an event waits for a lossless receiver a full ring behind; None waits as long as it takes. |
None
|
on_full
|
Literal['wait', 'release']
|
What an event send does when |
'wait'
|
Raises:
| Type | Description |
|---|---|
SegmentExistsError
|
If the creator of a channel of that name still runs. |
__call__
¶
Send the document doc named name.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a descriptor holds a key an event stream cannot carry, an event does not match its descriptor, or its descriptor was not sent on this channel. Nothing is sent then. |
TypeError
|
If a document holds a value that cannot be encoded. |
TimeoutError
|
If an event waited |
DocumentReceiver
¶
DocumentReceiver(name: str, mode: Literal['lossless', 'lossy', 'latest'], control: SharedStream[ControlItem, Any])
Receives the documents of a channel, in the order they were sent.
Make one with attach, not
the constructor. The control stream is read without loss whatever the mode; the mode
applies to the event streams. Each receive reads the control
documents waiting, up to as many as the control stream's ring holds,
and opens the event stream of each descriptor among them before it
delivers the descriptor. A receiver attached mid-run delivers the run's
start and descriptors first, then the documents from its attach point
on, with the events sent since the last other document that their
streams still hold.
attach
classmethod
¶
Attach to the channel name.
Raises:
| Type | Description |
|---|---|
SegmentNotFoundError
|
If there is no channel of that name. |
LateJoinError
|
If the run under way has a state too large for the channel. |
WaiterSlotsFullError
|
If the channel has no free reader place: a receiver takes one on each event stream of the run under way, and on the control stream one when lossless, two when lossy or latest. |
receive
¶
Return the next document's name and the document.
Raises:
| Type | Description |
|---|---|
EndOfStream
|
If the sender closed or died and every document it sent that this receiver holds was delivered. |
ReceiverReleasedError
|
If the sender released this receiver, or a lossless receiver lost events of a stream it opened too late or found removed; it is closed then. |
TimeoutError
|
If |
StreamClosedError
|
If the receiver is closed. |
ReceiverReleasedError
¶
Bases: RuntimeError
The sender released the receiver, which lost documents and closed.
Attach a new receiver to go on from the run's state.
LateJoinError
¶
Bases: RuntimeError
The run under way has a state too large for the channel to store.
A receiver can attach again once the run has stopped.