Aliases
Link Method
- crappy.link(in_block, out_block, modifier: Iterable[Callable[[Dict[str, Any]], Dict[str, Any]]] | Callable[[Dict[str, Any]], Dict[str, Any]] | None = None, name: str | None = None) None [source]
Function linking two Blocks, allowing to send data from one to the other.
It instantiates a
Link
between two children ofBlock
.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.
modifier – Either a callable, or an iterable (like a
list
or atuple
) containing callables. If several given (in an iterable), they are called in the given order. They should preferably be children ofModifier
. Refer to the associated documentation 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.
New in version 1.4.0.
Changed in version 1.5.9: explicitly listing the condition, modifier, timeout, action and name arguments
Removed in version 2.0.0: condition, timeout and action arguments
Open Online Documentation
Classes aliases
- class crappy.Actuator(*_, **__)[source]
The base class for all Actuator classes, allowing to keep track of them and defining methods shared by all of them.
The Actuator objects are helper classes used by the
Machine
Block to communicate with motors or other actuators.New in version 1.4.0.
- class crappy.Block(*args, **kwargs)[source]
This class constitutes the base object in Crappy.
It is extremely versatile, and can perform a wide variety of actions during a test. Many Blocks are already defined in Crappy, but it is possible to define custom ones for specific purposes.
It is a subclass of
multiprocessing.Process
, and is thus an independent process in Python. It communicates with other Blocks viamultiprocessing
objects.This class also contains the class methods that allow driving a script with Crappy. They are always called in the __main__ Process, and drive the execution of all the children Blocks.
New in version 1.4.0.
- class crappy.Camera(*_, **__)[source]
Base class for every Camera object. Implements methods shared by all the Cameras, and ensures their dataclass is
MetaCamera
.The Camera objects are helper classes used by the
Camera
Block to interface with cameras.New in version 1.4.0.
- class crappy.InOut(*_, **__)[source]
Base class for all InOut objects. Implements methods shared by all the InOuts, and ensures their dataclass is MetaIO.
The InOut objects are helper classes used by the
IOBlock
to interface with hardware.New in version 1.4.0.
- class crappy.Modifier(*_, **__)[source]
The base class for all Modifier classes, simply allowing to keep track of them.
The Modifiers allow altering data from an input
Block
before it gets sent to an output Block. Each Modifier is associated to aLink
linking the two Blocks. It is passed as an argument of thelink()
method instantiating the Link.It is preferable for every Modifier to be a child of this class, although that is not mandatory. A Modifier only needs to be a callable, i.e. a class defining the
__call__()
method or a function.New in version 1.4.0.
Methods aliases
crappy.prepare()
- classmethod Block.prepare_all(log_level: int | None = 10) None [source]
Creates the synchronization objects, shares them with the Blocks, and starts the
Process
associated to the Blocks.Also initializes the
Logger
for the Crappy script.Once started with this method, the Blocks will call their
prepare()
method and then be blocked by amultiprocessing.Barrier
.If an error is caught at a moment when the Blocks might already be running, performs an extensive cleanup to ensure everything stops as expected.
- Parameters:
log_level –
The maximum logging level that will be handled by Crappy. By default, it is set to the lowest level (
DEBUG
) so that all messages are handled. If set to a higher level, the levels specified for each Block with thedebug
argument may be ignored. If set toNone
, logging is totally disabled. Refer to the documentation of thelogging
module for information on the possible levels.New in version 2.0.0.
Removed in version 2.0.0: verbose argument
crappy.renice()
- classmethod Block.renice_all(allow_root: bool) None [source]
On Linux and macOS, renices the
Process
associated with the Blocks.On Windows, does nothing.
If an error is caught, performs an extensive cleanup to ensure everything stops as expected.
- Parameters:
allow_root –
If set to
True
, tries to renice the Processes with sudo privilege in Linux. It requires the Python script to be run with sudo privilege, otherwise it has no effect.Changed in version 2.0.0: renamed from high_prio to allow_root
crappy.launch()
- classmethod Block.launch_all(no_raise: bool = False) None [source]
The final method being called by the main
Process
running a script with Crappy.It unlocks all the Blocks by releasing the synchronization
Barrier
, sets the shared t0Value
, and then waits for all the Blocks to finish.In case an exception is raised, sets the stop
Event
for warning the Blocks, waits for the Blocks to finish, and if they don’t, terminates them.- Parameters:
no_raise – When set to
False
, the Exceptions encountered during Crappy’s execution, as well as theKeyboardInterrupt
, will raise an Exception right before Crappy returns. This is meant to prevent the execution of code that would come after Crappy, in case Crappy does not terminate as expected. This behavior can be disabled by setting this argument toTrue
.
Removed in version 2.0.0: t0, verbose and bg arguments
crappy.start()
- classmethod Block.start_all(allow_root: bool = False, log_level: int | None = 10, no_raise: bool = False) None [source]
Method for starting a script with Crappy.
It sets the synchronization objects for all the Blocks, renices the corresponding
Process
and starts the Blocks.The call to this method is blocking until Crappy finishes.
Note
It is possible to have a finer grained control of the start of a Crappy script with the methods
prepare_all()
,renice_all()
andlaunch_all()
.- Parameters:
allow_root –
If set to
True
, tries to renice the Processes with sudo privilege in Linux. It requires the Python script to be run with sudo privilege, otherwise it has no effect.Changed in version 2.0.0: renamed from high_prio to allow_root
log_level –
The maximum logging level that will be handled by Crappy. By default, it is set to the lowest level (
DEBUG
) so that all messages are handled. If set to a higher level, the levels specified for each Block with thedebug
argument may be ignored. If set toNone
, logging is totally disabled. Refer to the documentation of thelogging
module for information on the possible levels.New in version 2.0.0.
no_raise –
When set to
False
, the Exceptions encountered during Crappy’s execution, as well as theKeyboardInterrupt
, will raise an Exception right before Crappy returns. This is meant to prevent the execution of code that would come after Crappy, in case Crappy does not terminate as expected. This behavior can be disabled by setting this argument toTrue
.New in version 2.0.0.
Removed in version 2.0.0: t0, verbose, bg arguments
crappy.stop()
crappy.reset()
- classmethod Block.reset() None [source]
Resets Crappy by emptying the
WeakSet
containing references to all the Blocks and resetting the synchronization objects.This method is called at the very end of the
_cleanup()
method, but can also be called to “revert” the instantiation of Blocks while Crappy isn’t started yet.