gemseo.disciplines.wrappers.retry_discipline module#

The retry discipline.

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

Bases: Discipline

A discipline to be executed with retry and timeout options.

This Discipline wraps another discipline so 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. The timeout can be handled either via a thread or a subprocess. By default, it is handled by a thread, this can be changed by setting the timeout_with_process argument to True. Use a thread when the discipline does not create other processes, otherwise those processes will keep running after the timeout duration. Beware that using a process is slower, especially under Windows.

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 ().

  • timeout_with_process (bool) --

    Whether to use a process or a thread when using the timeout feature.

    By default it is set to False.

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).