當前位置: 首頁>>代碼示例>>Python>>正文


Python LaxBoundedSemaphore.clear方法代碼示例

本文整理匯總了Python中LaxBoundedSemaphore.clear方法的典型用法代碼示例。如果您正苦於以下問題:Python LaxBoundedSemaphore.clear方法的具體用法?Python LaxBoundedSemaphore.clear怎麽用?Python LaxBoundedSemaphore.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在LaxBoundedSemaphore的用法示例。


在下文中一共展示了LaxBoundedSemaphore.clear方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_clear

# 需要導入模塊: import LaxBoundedSemaphore [as 別名]
# 或者: from LaxBoundedSemaphore import clear [as 別名]
    def test_clear(self):
        x = LaxBoundedSemaphore(10)
        for i in range(11):
            x.acquire(Mock())
        self.assertTrue(x._waiting)
        self.assertEqual(x.value, 0)

        x.clear()
        self.assertFalse(x._waiting)
        self.assertEqual(x.value, x.initial_value)
開發者ID:NotSqrt,項目名稱:celery,代碼行數:12,代碼來源:test_hub.py

示例2: test_clear

# 需要導入模塊: import LaxBoundedSemaphore [as 別名]
# 或者: from LaxBoundedSemaphore import clear [as 別名]
    def test_clear(self):
        x = LaxBoundedSemaphore(10)
        for i in range(11):
            x.acquire(Mock())
        assert x._waiting
        assert x.value == 0

        x.clear()
        assert not x._waiting
        assert x.value == x.initial_value
開發者ID:Erve1879,項目名稱:kombu,代碼行數:12,代碼來源:test_hub.py

示例3: test_grow_shrink

# 需要導入模塊: import LaxBoundedSemaphore [as 別名]
# 或者: from LaxBoundedSemaphore import clear [as 別名]
    def test_grow_shrink(self):
        x = LaxBoundedSemaphore(1)
        self.assertEqual(x.initial_value, 1)
        cb1 = Mock()
        x.acquire(cb1, 1)
        cb1.assert_called_with(1)
        self.assertEqual(x.value, 0)

        cb2 = Mock()
        x.acquire(cb2, 2)
        self.assertFalse(cb2.called)
        self.assertEqual(x.value, 0)

        cb3 = Mock()
        x.acquire(cb3, 3)
        self.assertFalse(cb3.called)

        x.grow(2)
        cb2.assert_called_with(2)
        cb3.assert_called_with(3)
        self.assertEqual(x.value, 3)
        self.assertEqual(x.initial_value, 3)

        self.assertFalse(x._waiting)
        x.grow(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        x.clear()

        x.shrink(3)
        for i in range(x.initial_value):
            self.assertTrue(x.acquire(Mock()))
        self.assertFalse(x.acquire(Mock()))
        self.assertEqual(x.value, 0)

        for i in range(100):
            x.release()
        self.assertEqual(x.value, x.initial_value)
開發者ID:NotSqrt,項目名稱:celery,代碼行數:41,代碼來源:test_hub.py

示例4: test_grow_shrink

# 需要導入模塊: import LaxBoundedSemaphore [as 別名]
# 或者: from LaxBoundedSemaphore import clear [as 別名]
    def test_grow_shrink(self):
        x = LaxBoundedSemaphore(1)
        assert x.initial_value == 1
        cb1 = Mock()
        x.acquire(cb1, 1)
        cb1.assert_called_with(1)
        assert x.value == 0

        cb2 = Mock()
        x.acquire(cb2, 2)
        cb2.assert_not_called()
        assert x.value == 0

        cb3 = Mock()
        x.acquire(cb3, 3)
        cb3.assert_not_called()

        x.grow(2)
        cb2.assert_called_with(2)
        cb3.assert_called_with(3)
        assert x.value == 2
        assert x.initial_value == 3

        assert not x._waiting
        x.grow(3)
        for i in range(x.initial_value):
            assert x.acquire(Mock())
        assert not x.acquire(Mock())
        x.clear()

        x.shrink(3)
        for i in range(x.initial_value):
            assert x.acquire(Mock())
        assert not x.acquire(Mock())
        assert x.value == 0

        for i in range(100):
            x.release()
        assert x.value == x.initial_value
開發者ID:Erve1879,項目名稱:kombu,代碼行數:41,代碼來源:test_hub.py


注:本文中的LaxBoundedSemaphore.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。