当前位置: 首页>>代码示例>>Python>>正文


Python retrying.Retrying方法代码示例

本文整理汇总了Python中retrying.Retrying方法的典型用法代码示例。如果您正苦于以下问题:Python retrying.Retrying方法的具体用法?Python retrying.Retrying怎么用?Python retrying.Retrying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在retrying的用法示例。


在下文中一共展示了retrying.Retrying方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: retry_on_exception

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def retry_on_exception(*args):
    """Takes a list of exceptions to retry on and retries, will automatically unpack ActivityTaskFailedError exceptions

    :param *args: exception classes to retry on
    :type *args: Iterable
    :rtype: function
    :return: callable function to be used with retry_on_exception in Retrying
    """
    def _retry_exceptions(exception):

        if isinstance(exception, ActivityTaskFailedError):
            exception = exception.cause

        if isinstance(exception, args):
            return True

        return False

    return _retry_exceptions 
开发者ID:boto,项目名称:botoflow,代码行数:21,代码来源:activity_retrying.py

示例2: initialized_retry

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def initialized_retry(*dargs, **dkw):
    def wrap(f):
        @wraps(f)
        def wrapped_f(*args, **kw):
            if _retry_init:
                rargs, rkw = _retry_init(dargs, dkw)
            else:
                rargs, rkw = dargs, dkw
            return Retrying(*rargs, **rkw).call(_warn_about_exceptions(f), *args, **kw)

        return wrapped_f

    return wrap

# for operations that shouldn't take longer than a few seconds (e.g. HTTP request)
# will retry after 2s, 4s, 8s, 10s, 10s, 10s ... until the 10th attempt 
开发者ID:scrapinghub,项目名称:exporters,代码行数:18,代码来源:default_retries.py

示例3: __init__

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def __init__(self, stop_max_attempt_number=None, stop_max_delay=None, wait_fixed=None,
                 wait_random_min=None, wait_random_max=None, wait_incrementing_start=None,
                 wait_incrementing_increment=None, wait_exponential_multiplier=None, wait_exponential_max=None,
                 retry_on_exception=None, retry_on_result=None, wrap_exception=False, stop_func=None, wait_func=None):

        super(Retrying, self).__init__(stop=stop_func, wait=wait_func, stop_max_attempt_number=stop_max_attempt_number,
                                       stop_max_delay=stop_max_delay, wait_fixed=wait_fixed,
                                       wait_random_min=wait_random_min,
                                       wait_random_max=wait_random_max, wait_incrementing_start=wait_incrementing_start,
                                       wait_incrementing_increment=wait_incrementing_increment,
                                       wait_exponential_multiplier=wait_exponential_multiplier,
                                       wait_exponential_max=wait_exponential_max, retry_on_exception=retry_on_exception,
                                       retry_on_result=retry_on_result,
                                       wrap_exception=wrap_exception,
                                       stop_func=stop_func, wait_func=wait_func)

        # unfortunately retrying uses ms everywhere and we are using seconds (as in floats 0.5 is valid)
        # to remain consistent with botoflow, we fix all the times before passing the to retrying

        self._stop_max_attempt_number = 3 if stop_max_attempt_number is None else stop_max_attempt_number
        self._stop_max_delay = 1000 if stop_max_delay is None else int(stop_max_delay * 1000)
        self._wait_fixed = 1000 if wait_fixed is None else int(wait_fixed * 1000)
        self._wait_random_min = 0 if wait_random_min is None else int(wait_random_min * 1000)
        self._wait_random_max = 1000 if wait_random_max is None else int(wait_random_max * 1000)
        self._wait_incrementing_start = 0 if wait_incrementing_start is None else int(wait_incrementing_start * 1000)
        self._wait_incrementing_increment = (1000 if wait_incrementing_increment is None
                                             else int(wait_incrementing_increment * 1000))
        self._wait_exponential_multiplier = (1 if wait_exponential_multiplier is None
                                             else int(wait_exponential_multiplier * 1000))
        self._wait_exponential_max = (retrying.MAX_WAIT if wait_exponential_max is None
                                      else int(wait_exponential_max * 1000)) 
开发者ID:boto,项目名称:botoflow,代码行数:33,代码来源:activity_retrying.py

示例4: _warn_about_exceptions

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def _warn_about_exceptions(f, *args, **kw):
    try:
        return f(*args, **kw)
    except Exception as e:
        logging.warning("Retrying: {} (message was: {})".format(
            f.__name__, str(e)))
        raise 
开发者ID:scrapinghub,项目名称:exporters,代码行数:9,代码来源:default_retries.py

示例5: retry_generator

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def retry_generator(fn=None, max_retries=8, retry_multiplier=5.0, *args, **kwargs):
    @decorator
    def _decor_(fn, *args, **kwargs):
        """
        Retry a generator. The if you don't expect already yielded items to be
        yielded again, the generator will need to keep state about what items have
        already been successfully yielded.
        """
        for retry in range(1, max_retries + 1):
            try:
                generator = fn(*args, **kwargs)
                if not isinstance(generator, GeneratorType):
                    msg = "@retry_generator cannot be used in non-generator functions"
                    raise NonGeneratorError(msg)

                for i in generator:
                    yield i
            except (StopIteration, NonGeneratorError):
                raise
            except Exception as e:
                if retry < max_retries:
                    logging.warning("Retrying: {} (message was: {})".format(
                        fn.__name__, str(e)))
                    time.sleep(retry * retry_multiplier)
                else:
                    raise
            else:
                break

    return _decor_(fn, *args, **kwargs) if fn is not None else _decor_ 
开发者ID:scrapinghub,项目名称:exporters,代码行数:32,代码来源:default_retries.py

示例6: retry

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def retry(method_to_check, retry_timeout=RETRY_TIMEOUT,
              retry_interval=RETRY_INTERVAL):
        return Retrying(stop_max_delay=retry_timeout * 1000,
                        wait_fixed=retry_interval * 1000).call(method_to_check) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:6,代码来源:base_product_case.py

示例7: db_func_with_retry

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def db_func_with_retry(db_func, *args, **kwargs):
    """
    This method is a generic retry function to support database setup and cleanup.
    """
    # Using as an annotation would be nice but annotations are evaluated at import
    # time and simple ways to use the annotation means the config gets read before
    # it is setup. Likely there is a way to use some proxies to delay the actual
    # reading of config values however this is lesser code.
    retrying_obj = retrying.Retrying(
        retry_on_exception=_retry_if_connection_error,
        wait_exponential_multiplier=cfg.CONF.database.connection_retry_backoff_mul * 1000,
        wait_exponential_max=cfg.CONF.database.connection_retry_backoff_max_s * 1000,
        stop_max_delay=cfg.CONF.database.connection_retry_max_delay_m * 60 * 1000
    )
    return retrying_obj.call(db_func, *args, **kwargs) 
开发者ID:StackStorm,项目名称:st2,代码行数:17,代码来源:db_init.py

示例8: register_exchanges_with_retry

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def register_exchanges_with_retry():
    def retry_if_io_error(exception):
        return isinstance(exception, socket.error)

    retrying_obj = retrying.Retrying(
        retry_on_exception=retry_if_io_error,
        wait_fixed=cfg.CONF.messaging.connection_retry_wait,
        stop_max_attempt_number=cfg.CONF.messaging.connection_retries
    )
    return retrying_obj.call(register_exchanges) 
开发者ID:StackStorm,项目名称:st2,代码行数:12,代码来源:bootstrap_utils.py

示例9: _get

# 需要导入模块: import retrying [as 别名]
# 或者: from retrying import Retrying [as 别名]
def _get(self, url, package):
        retry = Retrying(wait_exponential_multiplier=2000, wait_exponential_max=120000,
            retry_on_exception=_retry_msg)

        return retry.call(requests.get, url % package) 
开发者ID:droope,项目名称:droopescan,代码行数:7,代码来源:silverstripe.py


注:本文中的retrying.Retrying方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。