pycram.failure_handling#

Classes#

FailureHandling

Base class for failure handling mechanisms in automated systems or workflows.

Retry

A subclass of FailureHandling that implements a retry mechanism.

RetryMonitor

A subclass of FailureHandling that implements a retry mechanism that works with a Monitor.

Functions#

try_action(action, failure_type[, max_tries])

A generic function to retry an action a certain number of times before giving up, with a specific failure type.

try_motion(motion, motion_designator_instance, ...[, ...])

A generic function to retry a motion a certain number of times before giving up, with a specific exception.

try_method(method, failure_type[, max_tries, name])

A generic function to retry a method a certain number of times before giving up, with a specific exception.

Module Contents#

class pycram.failure_handling.FailureHandling(plan: typing_extensions.Optional[pycram.plan.Plan] = None)#

Bases: pycram.language.LanguageMixin

Base class for failure handling mechanisms in automated systems or workflows.

This class provides a structure for implementing different strategies to handle failures that may occur during the execution of a plan or process. It is designed to be extended by subclasses that implement specific failure handling behaviors.

plan = None#
abstract perform()#

Abstract method to perform the failure handling mechanism.

This method should be overridden in subclasses to implement the specific behavior for handling failures.

Raises:

NotImplementedError – If the method is not implemented in a subclass.

class pycram.failure_handling.Retry(plan: pycram.language.MonitorPlan, max_tries: int = 3)#

Bases: FailureHandling

A subclass of FailureHandling that implements a retry mechanism.

This class represents a specific failure handling strategy where the system attempts to retry a failed action a certain number of times before giving up.

max_tries: int#

The maximum number of attempts to retry the action.

perform() typing_extensions.List[typing_extensions.Any]#

Implementation of the retry mechanism.

This method attempts to perform the action specified in the designator_description. If the action fails, it is retried up to max_tries times. If all attempts fail, the last exception is raised.

Raises:

PlanFailure – If all retry attempts fail.

class pycram.failure_handling.RetryMonitor(monitor_plan: pycram.plan.Plan, max_tries: int = 3, recovery: dict = None)#

Bases: FailureHandling

A subclass of FailureHandling that implements a retry mechanism that works with a Monitor.

This class represents a specific failure handling strategy that allows us to retry a demo that is being monitored, in case that monitoring condition is triggered.

max_tries: int#

The maximum number of attempts to retry the action.

recovery: dict#

A dictionary that maps exception types to recovery actions

lock#
perform() typing_extensions.List[typing_extensions.Any]#

This method attempts to perform the Monitor + plan specified in the designator_description. If the action fails, it is retried up to max_tries times. If all attempts fail, the last exception is raised. In every loop, we need to clear the kill_event, and set all relevant ‘interrupted’ variables to False, to make sure the Monitor and plan are executed properly again.

Raises:

PlanFailure – If all retry attempts fail.

Returns:

The state of the execution performed, as well as a flattened list of the

results, in the correct order

pycram.failure_handling.try_action(action: typing_extensions.Any, failure_type: typing_extensions.Type[Exception], max_tries: int = 3)#

A generic function to retry an action a certain number of times before giving up, with a specific failure type.

Parameters:
  • action – The action to be performed, it must have a perform() method.

  • failure_type – The type of exception to catch.

  • max_tries – The maximum number of attempts to retry the action. Defaults to 3.

pycram.failure_handling.try_motion(motion: pycram.process_module.ProcessModule, motion_designator_instance: pycram.designator.BaseMotion, failure_type: typing_extensions.Type[Exception], max_tries: int = 3)#

A generic function to retry a motion a certain number of times before giving up, with a specific exception.

Parameters:
  • motion – The motion to be executed.

  • motion_designator_instance – The instance of the motion designator that has the description of the motion.

  • failure_type – The type of exception to catch.

  • max_tries – The maximum number of attempts to retry the motion.

pycram.failure_handling.try_method(method: typing_extensions.Callable, failure_type: typing_extensions.Type[Exception], max_tries: int = 3, name: str = 'method')#

A generic function to retry a method a certain number of times before giving up, with a specific exception.

Parameters:
  • method – The method to be called.

  • failure_type – The type of exception to catch.

  • max_tries – The maximum number

  • name – The name of the method to be called.