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


Python tenacity.wait_random方法代码示例

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


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

示例1: __enter__

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def __enter__(self):
        self.lock = False
        if not self.coordinator:
            return self

        LOG.debug("Trying to acquire lock for %s", self.locks_prefix)
        names = itertools.cycle(self.lock_names)
        retry_kwargs = {'wait': tenacity.wait_random(min=0, max=1),
                        'reraise': True}
        if self.timeout:
            retry_kwargs['stop'] = tenacity.stop_after_delay(self.timeout)

        @tenacity.retry(**retry_kwargs)
        def grab_lock_from_pool():
            name = next(names)
            # NOTE(pas-ha) currently all tooz backends support locking API.
            # In case this changes, this should be wrapped to not respin
            # lock grabbing on NotImplemented exception.
            lock = self.coordinator.get_lock(name.encode())
            locked = lock.acquire(blocking=False)
            if not locked:
                raise coordination.LockAcquireFailed(
                    "Failed to acquire lock %s" % name)
            return lock

        try:
            self.lock = grab_lock_from_pool()
        except Exception:
            msg = ("Failed to acquire any of %s locks for %s "
                   "for a netmiko action in %s seconds. "
                   "Try increasing acquire_timeout." % (
                       self.locks_pool_size, self.locks_prefix,
                       self.timeout))
            LOG.error(msg, exc_info=True)
            raise
        return self 
开发者ID:openstack,项目名称:networking-generic-switch,代码行数:38,代码来源:locking.py

示例2: test_random_sleep

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def test_random_sleep(self):
        r = Retrying(wait=tenacity.wait_random(min=1, max=20))
        times = set()
        for x in six.moves.range(1000):
            times.add(r.wait(1, 6546))

        # this is kind of non-deterministic...
        self.assertTrue(len(times) > 1)
        for t in times:
            self.assertTrue(t >= 1)
            self.assertTrue(t < 20) 
开发者ID:jd,项目名称:tenacity,代码行数:13,代码来源:test_tenacity.py

示例3: test_random_sleep_without_min

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def test_random_sleep_without_min(self):
        r = Retrying(wait=tenacity.wait_random(max=2))
        times = set()
        times.add(r.wait(1, 6546))
        times.add(r.wait(1, 6546))
        times.add(r.wait(1, 6546))
        times.add(r.wait(1, 6546))

        # this is kind of non-deterministic...
        self.assertTrue(len(times) > 1)
        for t in times:
            self.assertTrue(t >= 0)
            self.assertTrue(t <= 2) 
开发者ID:jd,项目名称:tenacity,代码行数:15,代码来源:test_tenacity.py

示例4: test_wait_combine

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def test_wait_combine(self):
        r = Retrying(wait=tenacity.wait_combine(tenacity.wait_random(0, 3),
                                                tenacity.wait_fixed(5)))
        # Test it a few time since it's random
        for i in six.moves.range(1000):
            w = r.wait(1, 5)
            self.assertLess(w, 8)
            self.assertGreaterEqual(w, 5) 
开发者ID:jd,项目名称:tenacity,代码行数:10,代码来源:test_tenacity.py

示例5: test_wait_double_sum

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def test_wait_double_sum(self):
        r = Retrying(wait=tenacity.wait_random(0, 3) + tenacity.wait_fixed(5))
        # Test it a few time since it's random
        for i in six.moves.range(1000):
            w = r.wait(1, 5)
            self.assertLess(w, 8)
            self.assertGreaterEqual(w, 5) 
开发者ID:jd,项目名称:tenacity,代码行数:9,代码来源:test_tenacity.py

示例6: test_wait_triple_sum

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_random [as 别名]
def test_wait_triple_sum(self):
        r = Retrying(wait=tenacity.wait_fixed(1) + tenacity.wait_random(0, 3) +
                     tenacity.wait_fixed(5))
        # Test it a few time since it's random
        for i in six.moves.range(1000):
            w = r.wait(1, 5)
            self.assertLess(w, 9)
            self.assertGreaterEqual(w, 6) 
开发者ID:jd,项目名称:tenacity,代码行数:10,代码来源:test_tenacity.py


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