holypipette.controller.base module

Module defining the TaskController class.

exception holypipette.controller.base.RequestedAbortException[source]

Bases: Exception

Exception that should be raised when a function aborts its execution due to abort_requested.

class holypipette.controller.base.TaskController[source]

Bases: LoggingObject

Base class for objects that control the high-level logic to control the hardware, e.g. the calibration of a manipulator or the steps to follow for a patch clamp experiment. Objects will usually be instantiated from more specific subclasses.

The class provides several convenient ways to interact with an asynchronously requested abort of the current task. A long-running task can check explicitly whether an abort has been requested with abort_if_requested which will raise a RequestedAbortException if the abort_requested attribute has been set. This check will also be performed automatically if debug, info, or warn is called (which otherwise simply forward their message to the logging system). Finally, tasks should call sleep (instead of time.sleep) which will periodically check for an abort request during the sleep time.

abort_if_requested()[source]

Checks for an abort request and interrupts the current task if necessary. Can be explicitly called during long-running tasks, but will also be called automatically by the logging functions debug, info, warn, or the wait function sleep. :raises RequestedAbortException: If the abort_requested attribute is set

delete_state()[source]

Delete any previously saved state. By default, overwrites the saved_state attribute with None.

has_saved_state()[source]

Whether this object has a saved state that can be recovered with recover_state.

Returns:

has_state – Whether this object has a saved state. By default, checks whether the saved_state attribute is not None.

Return type:

bool

recover_state()[source]

Recover the state (e.g. the position of the manipulators) after a failure or abort. Has to be overwritten in subclasses.

save_state()[source]

Save the current state (e.g. the position of the manipulators) for later recovery in the case of a failure or abort. Has to be overwritten in subclasses. Should save the state to the saved_state variable or overwrite has_saved_state as well.

sleep(seconds)[source]

Convenience function that sleeps (as time.sleep) but remains sensitive to abort requests

holypipette.controller.base.check_for_abort(obj, func)[source]

Decorator to make a function raise a RequestedAbortException if abort_requested attribute is set.