def exp_backoff_fn(fn, *args, **kwargs):
 max_tries = kwargs.pop(u'max_tries', MAX_TRIES)
 if (not on_win):
  return fn(*args, **kwargs)
 import random
 for n in range(max_tries):
  try:
   result = fn(*args, **kwargs)
  except (OSError, IOError) as e:
   log.trace(repr(e))
   if (e.errno in (EPERM, EACCES)):
    if (n == (max_tries - 1)):
     raise
    sleep_time = (((2 ** n) + random.random()) * 0.1)
    caller_frame = sys._getframe(1)
    log.trace(u'retrying %s/%s %s() in %g sec', basename(caller_frame.f_code.co_filename), caller_frame.f_lineno, fn.__name__, sleep_time)
    sleep(sleep_time)
   elif (e.errno in (ENOENT, ENOTEMPTY)):
    raise
   else:
    log.warn(u'Uncaught backoff with errno %s %d', errorcode[e.errno], e.errno)
    raise
  else:
   return result

def exp_backoff_fn ( fn , * args , ** kwargs ) : max_tries = kwargs . pop ( u'max_tries' , MAX_TRIES ) if ( not on_win ) : return fn ( * args , ** kwargs ) import random for n in range ( max_tries ) : try : result = fn ( * args , ** kwargs ) except ( OSError , IOError ) as e : log . trace ( repr ( e ) ) if ( e . errno in ( EPERM , EACCES ) ) : if ( n == ( max_tries - 1 ) ) : raise sleep_time = ( ( ( 2 ** n ) + random . random ( ) ) * 0.1 ) caller_frame = sys . _getframe ( 1 ) log . trace ( u'retrying %s/%s %s() in %g sec' , basename ( caller_frame . f_code . co_filename ) , caller_frame . f_lineno , fn . __name__ , sleep_time ) sleep ( sleep_time ) elif ( e . errno in ( ENOENT , ENOTEMPTY ) ) : raise else : log . warn ( u'Uncaught backoff with errno %s %d' , errorcode [ e . errno ] , e . errno ) raise else : return result
mostly for retrying file operations that fail on windows due to virus scanners .