Links
Link
- class crappy.links.link.Link(input_block=None, output_block=None, conditions: Optional[List[Union[Callable, crappy.modifier.modifier.Modifier]]] = None, modifiers: Optional[List[Union[Callable, crappy.modifier.modifier.Modifier]]] = None, timeout: float = 1, action: Literal['warn', 'kill', 'NoWarn'] = 'warn', name: Optional[str] = None)[source]
This class is used for transferring information between the blocks.
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
You can add one or multiple Modifiers to modify the transferred value. The modifiers should either be children of Modifier or callables taking a
dict
as argument and returning adict
.- __init__(input_block=None, output_block=None, conditions: Optional[List[Union[Callable, crappy.modifier.modifier.Modifier]]] = None, modifiers: Optional[List[Union[Callable, crappy.modifier.modifier.Modifier]]] = None, timeout: float = 1, action: Literal['warn', 'kill', 'NoWarn'] = 'warn', name: Optional[str] = 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.
conditions – Deprecated, kept only for backward-compatibility.
modifiers – A
list
containing children of Modifier and/or callables. If several objects given ,they will be called in the given order. See Modifiers for more information.timeout – Sets a timeout for sending the data in the link.
action –
Action to perform in case of a
TimeoutError
during thesend()
method. Should be in:'warn', 'kill', 'NoWarn',
any other value would be for debugging.
name – Name of the link, to differentiate it from the others when debugging. If no specific name is given, the links are anyway numbered in the order in which they are instantiated in the code.
- recv(blocking: bool = True) Optional[Dict[str, Any]] [source]
Receives data from a link and returns it as a dict.
- Parameters
blocking (
bool
, optional) – Enables (True
) or disables (False
) blocking mode.- Returns
If
blocking
isTrue
,recv()
method will wait until data is available in the pipe and return the received data. Otherwise, it will check if there is data available to return, or returnNone
if the pipe is empty.
- recv_chunk(blocking: bool = True) Optional[Dict[str, list]] [source]
Returns all the data waiting in a link.
- recv_chunk_no_stop() Optional[Dict[str, Any]] [source]
Experimental feature, to be used in
finish()
methods to recover the final remaining data (possibly after a stop signal).
- recv_delay(delay: float) Dict[str, Any] [source]
Same as
recv_chunk()
except it runs for a given delay no matter if the link is empty or not.Useful for blocks with a low looping frequency that don’t need data so frequently.
Note
All the
recv()
calls are blocking so this method will take at leastdelay
seconds to return, but it could be more since it may wait for data.Also, it will return at least one reading.
- recv_last(blocking: bool = False) Optional[Dict[str, Any]] [source]
Returns only the last value in the pipe, dropping all the others.
Note
If
blocking
isFalse
, will returnNone
if there is no data waiting.If
blocking
isTrue
, will wait for at least one data.Warning
Unlike
recv()
, default is non blocking.
- crappy.links.link.link(in_block, out_block, condition: Optional[Union[List[Union[Callable, crappy.modifier.modifier.Modifier]], crappy.modifier.modifier.Modifier, Callable]] = None, modifier: Optional[Union[List[Union[Callable, crappy.modifier.modifier.Modifier]], crappy.modifier.modifier.Modifier, Callable]] = None, timeout: float = 1, action: Literal['warn', 'kill', 'NoWarn'] = 'warn', name: Optional[str] = None) NoReturn [source]
Function linking two blocks, allowing to send data from one to the other.
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.- Parameters
in_block – The Block sending data through the link.
out_block – The Block receiving data through the link.
condition – Deprecated, kept only for backward-compatibility.
modifier – Either a child class of Modifier, or a callable, or a
list
containing such objects. If several given (in a list), calls them in the given order. See Modifiers for more information.timeout – Sets a timeout for sending the data in the link.
action –
Action to perform in case of a
TimeoutError
during thesend()
method. Should be in:'warn', 'kill', 'NoWarn',
any other value would be for debugging.
name – Name of the link, to differentiate it from the others when debugging. If no specific name is given, the links are anyway numbered in the order in which they are instantiated in the code.