Block
- class crappy.blocks.block.Block(*args, **kwargs)[source]
This represent a Crappy block, it must be parent of all the blocks.
- begin() None [source]
If
main()
is not overridden, this method will be called first, before entering the main loop.
- drop(num: list | str | None = None) None [source]
Will clear the inputs of the blocks.
This method performs like
get_last()
, but returnsNone
instantly.
- finish() None [source]
If
main()
is not overridden, this method will be called upon exit or after a crash.
- get_all_last(blocking: bool = True) Dict[str, list] [source]
To get the data from all links of the block.
It is almost the same as
get_last()
, but will return all the data that goes through the links (aslist
).Also, if multiple links have the same label, only the last link’s value will be kept.
- Parameters:
blocking – If
True
, blocks until there’s at least one value received for each label.
- get_last(blocking: bool = True) Dict[str, Any] [source]
To get the latest value of each labels from all inputs.
Warning
Unlike the
recv
methods of Link, this method is NOT guaranteed to return all the data going through the links!It is meant to get the latest values, discarding all the previous ones (for a displayer for example).
Its mode of operation is completely different since it can operate on multiple inputs at once.
Note
The first call may be blocking until it receives data, all the others will return instantaneously, giving the latest known reading.
- handle_freq() None [source]
For block with a given number of loops/s (use
freq
attribute to set it).
- launch(t0: float) None [source]
To start the
main()
method, will callProcess.start()
if needed.Once the process is started, calling launch will set the starting time and actually start the main method.
- Parameters:
t0 (
float
) – Time to set as starting time of the block (mandatory, in seconds after epoch).
- main() None [source]
This is where you define the main loop of the block.
Important
If not overridden, will raise an error.
- poll() bool [source]
Tells if any input link has pending data
Returns True if l.poll() is True for any input link l.
- prepare() None [source]
This will be run when creating the process, but before the actual start.
The first code to be run in the new process, will only be called once and before the actual start of the main launch of the blocks.
It can remain empty and do nothing.
- classmethod prepare_all(verbose: bool = True) None [source]
Starts all the blocks processes (
block.prepare
), but not the main loop.
- recv_all() Dict[str, list] [source]
Receives new data from all the inputs (not as chunks).
It will simply call
Pipe.recv()
on all non empty links and return a singledict
.Important
If the same label comes from multiple links, it may be overridden !
- recv_all_delay(delay: float | None = None, poll_delay: float = 0.1) List[Dict[str, list]] [source]
Method to wait for data, but continuously reading all the links to make sure they do not saturate.
- Parameters:
- Returns:
A
list
where each entry is what would have been returned byLink.recv_chunk()
on each link.
- recv_all_last() Dict[str, float] [source]
Like recv_all, but drops older data to return only the latest value
This method avoids Pipe congestion that can be induced by recv_all when the receiving block is slower than the block upstream
- classmethod renice_all(high_prio: bool = True, **_) None [source]
Will renice all the blocks processes according to
block.niceness
value.Note
If
high_prio
isFalse
, blocks with a negative niceness value will be ignored.This is to avoid asking for the
sudo
password since only root can lower the niceness of processes.
- send(data: Dict[str, float] | List[float]) None [source]
To send the data to all blocks downstream.
Send has 2 ways to operate. You can either build the
dict
yourself, or you can defineself.labels
(usually time first) and call send with alist
. It will then map them to thedict
.Note
ONLY
dict
can go through links.