Aliases

Open Online Documentation

crappy.docs()[source]

Opens the online documentation of Crappy.

It opens the latest version, and of course requires an internet access.

New in version 1.5.5.

Changed in version 2.0.0: renamed from doc to docs

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 via multiprocessing 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 a Link linking the two Blocks. It is passed as an argument of the link() 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.

class crappy.Path(*_, **__)[source]

Base class for all the Generator Path objects.

The Path object are used by the Generator Block to generate signals.

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 a multiprocessing.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 the debug argument may be ignored. If set to None, logging is totally disabled. Refer to the documentation of the logging 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 t0 Value, 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 the KeyboardInterrupt, 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 to True.

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() and launch_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 the debug argument may be ignored. If set to None, logging is totally disabled. Refer to the documentation of the logging 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 the KeyboardInterrupt, 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 to True.

    New in version 2.0.0.

Removed in version 2.0.0: t0, verbose, bg arguments

crappy.stop()

classmethod Block.stop_all() None[source]

Method for stopping all the Blocks by setting the stop Event.

Removed in version 2.0.0: verbose argument

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.