コード例 #1
0
def retry(attempts, func, *args, **kwargs):
    for _ in range(attempts):
        try:
            return func(*args, **kwargs)
        except Exception as err:
            if _is_retryable(err):
                sleep(0.01)
            raise
    raise
コード例 #2
0
 def get_multi(self, id_list):
     attempt_num = 0
     results = {}
     while id_list and attempt_num < self.max_retries:
         attempt_num += 1
         result = self.bucket.multiget(id_list, r=1)
         id_list = []
         for obj in result:
             # errors return a tuple of (bucket, key, err)
             if isinstance(obj, tuple):
                 err = obj[3]
                 if attempt_num == self.max_retries:
                     six.reraise(type(err), err)
                 elif _is_retryable(err):
                     id_list.append(obj[2])
                 else:
                     six.reraise(type(err), err)
             else:
                 results[obj.key] = obj.data
     return results