Package ganeti :: Package utils :: Module retry
[hide private]
[frames] | no frames]

Module retry

source code

Utility functions for retrying function calls with a timeout.

Classes [hide private]
  RetryTimeout
Retry loop timed out.
  RetryAgain
Retry again.
  _RetryDelayCalculator
Calculator for increasing delays.
Functions [hide private]
 
Retry(fn, delay, timeout, args=None, wait_fn=time.sleep, _time_fn=time.time)
Call a function repeatedly until it succeeds.
source code
Variables [hide private]
  RETRY_REMAINING_TIME = object()
Special delay to specify whole remaining timeout

Imports: time, errors


Function Details [hide private]

Retry(fn, delay, timeout, args=None, wait_fn=time.sleep, _time_fn=time.time)

source code 

Call a function repeatedly until it succeeds.

The function fn is called repeatedly until it doesn't throw RetryAgain anymore. Between calls a delay, specified by delay, is inserted. After a total of timeout seconds, this function throws RetryTimeout.

delay can be one of the following:

  • callable returning the delay length as a float
  • Tuple of (start, factor, limit)
  • RETRY_REMAINING_TIME to sleep until the timeout expires (this is useful when overriding wait_fn to wait for an external event)
  • A static delay as a number (int or float)
Parameters:
  • fn (callable) - Function to be called
  • delay - Either a callable (returning the delay), a tuple of (start, factor, limit) (see _RetryDelayCalculator), RETRY_REMAINING_TIME or a number (int or float)
  • timeout (float) - Total timeout
  • wait_fn (callable) - Waiting function
Returns:
Return value of function