Links
Link
- class crappy.links.link.Link(input_block=None, output_block=None, condition=None, modifier=None, timeout: float = 0.1, action: str = 'warn', name: str = 'link')[source]
Link class. All connections between Blocks should be made with this.
It creates a pipe and is used to transfer information between Blocks.
Note
You can add one or multiple Modifiers to modify the transferred value.
- __init__(input_block=None, output_block=None, condition=None, modifier=None, timeout: float = 0.1, action: str = 'warn', name: str = 'link') None [source]
Sets the instance attributes.
- Parameters
input_block –
output_block –
condition – Children class of
links.Condition
, for backward compatibility only. Can be a single condition or alist
of conditions that will be executed in the given order.modifier –
action (
str
, optional) –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 (
str
, optional) – Name of a link to recognize it on timeout.
- recv(blocking: bool = True) Optional[dict] [source]
Receives data.
- 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(length: int = 0) dict [source]
Allows you to receive a chunk of data.
If
length
> 0 it will return adict
containinglist
of the last length received data.If
length
= 0, it will return all the waiting data until the pipe is empty.If the pipe is already empty, it will wait to return at least one value.
- recv_chunk_nostop() Optional[dict] [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 [source]
Useful for blocks that don’t need data all so frequently.
It will continuously receive data for a given delay and return them as a single
dict
containinglist
of the values.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] [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.
- class crappy.links.link.MethodThread(target: Callable, args, kwargs)[source]
ThreadMethodThread, daemonic descendant class of
threading
.Thread which simply runs the specified target method with the specified arguments.
- run() None [source]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- crappy.links.link.error_if_string(recv: Callable) Callable [source]
Decorator to raise an error if the function returns a string.