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.

Parameters:
  • retry_timeout (num) –
  • retry_period (num) – sleep before retry
  • or None retry_on_error (callable) – 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
  • or None retry_on_error (callable) – 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
  • or None retry_on_error (callable) – checks whether an exception is eligible for retry