weakref

This module provides utility methods for retrying methods until they no longer fail.

exception RetryTimeoutError[source]
exception RetryError[source]
retry(retry_timeout=None, retry_period=None, retry_on_error=<function _default_retry_on_error>)[source]

Decorator for a method that needs to be executed until it not longer fails or until retry_on_error returns False.

The decorator arguments can be overriden by using them when calling the decorated method.

Generator functions are required to have a start_index argument which allows the method to start iterating from the last failure when called on retry.

Parameters
  • retry_timeout (num) –

  • retry_period (num) – sleep before retry

  • retry_on_error (callable or None) – checks whether an exception is eligible for retry

retry_contextmanager(retry_timeout=None, retry_period=None, retry_on_error=<function _default_retry_on_error>)[source]

Decorator to make a context manager from a method that needs to be entered until it no longer fails or until retry_on_error returns False.

The decorator arguments can be overriden by using them when calling the decorated method.

Parameters
  • retry_timeout (num) –

  • retry_period (num) – sleep before retry

  • retry_on_error (callable or None) – checks whether an exception is eligible for retry

retry_in_subprocess(retry_timeout=None, retry_period=None, retry_on_error=<function _default_retry_on_error>)[source]

Same as retry but it also retries segmentation faults.

As subprocesses are spawned, you cannot use this decorator with the “@” syntax because the decorated method needs to be an attribute of a module:

def _method(*args, **kw):
    ...

method = retry_in_subprocess()(_method)
Parameters
  • retry_timeout (num) –

  • retry_period (num) – sleep before retry

  • retry_on_error (callable or None) – checks whether an exception is eligible for retry