當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。