Links
Link
- class crappy.links.Link(*args, **kwargs)[source]
This class is used for transferring information between two instances of
Block
.The created Link is unidirectional, from the input Block to the output Block. Under the hood, a Link is basically a
multiprocessing.Pipe
with extra features.Note
It is possible to add one or multiple
Modifier
to modify the transferred value. The Modifiers should be callables taking adict
as argument and returning adict
. They can be functions, or preferably children ofModifier
.New in version 1.4.0.
- __init__(input_block, output_block, modifiers: List[Callable[[Dict[str, Any]], Dict[str, Any]]] | None = None, name: str | None = None) None [source]
Sets the instance attributes.
- Parameters:
input_block – The Block sending data through the Link.
output_block – The Block receiving data through the Link.
modifiers – A
list
containing callables. If several objects given, they will be called in the given order. Refer toModifier
for more information.name – Name of the Link, to differentiate it from the others when debugging. If no specific name is given, the Links are numbered in the order in which they are instantiated in the script.
Changed in version 1.5.9: renamed condition argument to conditions
Changed in version 1.5.9: renamed modifier argument to modifiers
Removed in version 2.0.0: conditions, timeout and action arguments
- log(log_level: int, msg: str) None [source]
Method for recording log messages from the Link.
- Parameters:
New in version 2.0.0.
- send(value: Dict[str, Any]) None [source]
Sends a value from the upstream Block to the downstream Block.
Before sending, applies the given Modifiers and makes sure there’s room in the Pipe for sending the data (Linux only).
- recv() Dict[str, Any] [source]
Reads a single value from the Link and returns it.
The read value is the oldest available in the Link, see
recv_last()
for reading the newest available value.If no data is available in the Link, returns an empty
dict
.- Returns:
A
dict
whose keys are the labels being sent, and for each key a single value (usually afloat
or astr
).
Removed in version 2.0.0: blocking argument
- recv_last() Dict[str, Any] [source]
Reads all the available values in the Link, and returns the newest one.
If no data is available in the Link, returns an empty
dict
. All the data that is not returned is permanently dropped.- Returns:
A
dict
whose keys are the labels being sent, and for each key a single value (usually afloat
or astr
).
Removed in version 2.0.0: blocking argument
- recv_chunk() Dict[str, List[Any]] [source]
Reads all the available values in the Link, and returns them all.
- Returns:
A
dict
whose keys are the labels being sent, and for each key alist
of the received values. The first item in the list is the oldest one available in the Link, the last item is the newest available.
Removed in version 1.5.9: length argument
New in version 1.5.9: blocking argument
Removed in version 2.0.0: blocking argument