Crappy
1.5
  • What is Crappy ?
  • Installation
  • Tutorials
  • Current functionalities
  • The complete list of Crappy blocks
    • Block
    • Actuators
    • Blocks
    • Cameras
    • Modifiers
    • In / Out
    • Links
      • Link
    • Tools
  • Documentation
  • Developers information
  • Bug reports
  • License information
Crappy
  • »
  • The complete list of Crappy blocks »
  • Links
  • View page source

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 a list of conditions that will be executed in the given order.

  • modifier –

  • timeout (float, optional) – Timeout for the send() method.

  • action (str, optional) –

    Action to perform in case of a TimeoutError during the send() 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.

Note

If blocking is False, returns None if there is no data.

Parameters

blocking (bool, optional) – Enables (True) or disables (False) blocking mode.

Returns

If blocking is True, 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 return None 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 a dict containing list 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 containing list of the values.

Note

All the recv() calls are blocking so this method will take AT LEAST delay 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 is False, will return None if there is no data waiting.

If blocking is True, will wait for at least one data.

Warning

Unlike recv(), default is NON blocking.

send(value: Union[dict, str]) → None[source]¶

Sends the value, or a modified value if you pass it through a modifier.

send_timeout(value: dict) → None[source]¶

Method for sending data with a given timeout on the link.

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.

exception crappy.links.link.TimeoutError[source]¶

Custom error to raise in case of timeout.

crappy.links.link.error_if_string(recv: Callable) → Callable[source]¶

Decorator to raise an error if the function returns a string.

crappy.links.link.link(in_block, out_block, **kwargs) → None[source]¶

Function that links two blocks.

Note

For the object, see Link.

crappy.links.link.win_timeout(timeout: Optional[float] = None) → Callable[source]¶

Decorator for adding a timeout to a link send.

Next Previous

© Copyright 2021.

Built with Sphinx using a theme provided by Read the Docs.