error.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:better-brenda 作者: simplecarnival 项目源码 文件源码
def retry(conf, action):
    n_retries = int(conf.get('N_RETRIES', '5'))
    reset_period = int(conf.get('RESET_PERIOD', '3600'))
    error_pause = int(conf.get('ERROR_PAUSE', '30'))

    reset = int(time.time())
    i = 0
    while True:
        try:
            ret = action()
        # These are the exception types that justify a retry -- extend this list as needed
        except (httplib.IncompleteRead, socket.error, boto.exception.BotoClientError, ValueErrorRetry), e:
            now = int(time.time())
            if now > reset + reset_period:
                print "******* RETRY RESET"
                i = 0
                reset = now
            i += 1
            print "******* RETRY %d/%d: %s" % (i, n_retries, e)
            if i < n_retries:
                print "******* WAITING %d seconds..." % (error_pause,)
                time.sleep(error_pause)
            else:
                raise ValueError("FAIL after %d retries" % (n_retries,))
        else:
            return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号