gemseo.disciplines.wrappers.retry_discipline module#

The retry discipline.

class RetryDiscipline(discipline, n_trials=5, wait_time=0.0, timeout=inf, fatal_exceptions=())[source]#

Bases: Discipline

A discipline to be executed with retry and timeout options.

This Discipline wraps another discipline.

It can be executed multiple times (up to a specified number of trials) if the previous attempts fail to produce any result.

A timeout in seconds can be specified to prevent executions from becoming stuck.

Users can also provide a tuple of Exception that, if one of them is raised, it does not retry the execution.

Please note that the TimeoutError exception is also caught if the wrapped discipline raises such an exception (i.e. aside from RetryDiscipline itself). So it could lead to 2 surprising cases, but in fact normal cases: - a TimeoutError exception even though the user didn't provide any timeout value. - a TimeoutError raised sooner than the timeout value set by the user.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • discipline (Discipline) -- The discipline to wrap in the retry loop.

  • n_trials (int) --

    The number of trials of the discipline.

    By default it is set to 5.

  • wait_time (float) --

    The time to wait between 2 trials (in seconds).

    By default it is set to 0.0.

  • timeout (float) --

    The maximum duration, in seconds, that the discipline is allowed to run. If this time limit is exceeded, the execution is terminated. If math.inf, the discipline is executed without timeout limit.

    By default it is set to inf.

  • fatal_exceptions (Iterable[type[Exception]]) --

    The exceptions for which the code raises an exception and exit immediately without retrying a run.

    By default it is set to ().

Raises:
  • TimeoutError -- If the timeout limit is reached.

  • Exception -- Other exceptions if an issue is encountered during the execution of discipline.

fatal_exceptions: Iterable[type[Exception]]#

The exceptions for which the code raises an exception and exit immediately without retrying a run.

property n_executions: int#

The number of times the discipline has been retried during execution.

n_trials: int#

The number of trials to execute the discipline.

timeout: float#

The maximum duration, in seconds, that the discipline is allowed to run.

wait_time: float#

The time to wait between 2 trials (in seconds).