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


Python LaxBoundedSemaphore.acquire方法代码示例

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


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

示例1: test_clear

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [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

示例2: test_clear

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [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

示例3: test_acquire_release

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [as 别名]
    def test_acquire_release(self):
        x = LaxBoundedSemaphore(2)

        c1 = Mock()
        x.acquire(c1, 1)
        self.assertEqual(x.value, 1)
        c1.assert_called_with(1)

        c2 = Mock()
        x.acquire(c2, 2)
        self.assertEqual(x.value, 0)
        c2.assert_called_with(2)

        c3 = Mock()
        x.acquire(c3, 3)
        self.assertEqual(x.value, 0)
        self.assertFalse(c3.called)

        x.release()
        self.assertEqual(x.value, 0)
        x.release()
        self.assertEqual(x.value, 1)
        x.release()
        self.assertEqual(x.value, 2)
        c3.assert_called_with(3)
开发者ID:EvaSDK,项目名称:celery,代码行数:27,代码来源:test_hub.py

示例4: test_acquire_release

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [as 别名]
    def test_acquire_release(self):
        x = LaxBoundedSemaphore(2)

        c1 = Mock()
        x.acquire(c1, 1)
        assert x.value == 1
        c1.assert_called_with(1)

        c2 = Mock()
        x.acquire(c2, 2)
        assert x.value == 0
        c2.assert_called_with(2)

        c3 = Mock()
        x.acquire(c3, 3)
        assert x.value == 0
        c3.assert_not_called()

        x.release()
        assert x.value == 0
        x.release()
        assert x.value == 1
        x.release()
        assert x.value == 2
        c3.assert_called_with(3)
开发者ID:Erve1879,项目名称:kombu,代码行数:27,代码来源:test_hub.py

示例5: test_grow_shrink

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [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

示例6: test_grow_shrink

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [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

示例7: test_over_release

# 需要导入模块: import LaxBoundedSemaphore [as 别名]
# 或者: from LaxBoundedSemaphore import acquire [as 别名]
    def test_over_release(self):
        x = LaxBoundedSemaphore(2)
        calls = []
        for i in range(1, 21):
            x.acquire(calls.append, i)
        x.release()
        x.acquire(calls.append, 'x')
        x.release()
        x.acquire(calls.append, 'y')

        self.assertEqual(calls, [1, 2, 3, 4])

        for i in range(30):
            x.release()
        self.assertEqual(calls, list(range(1, 21)) + ['x', 'y'])
        self.assertEqual(x.value, x.initial_value)

        calls[:] = []
        for i in range(1, 11):
            x.acquire(calls.append, i)
        for i in range(1, 11):
            x.release()
        self.assertEqual(calls, list(range(1, 11)))

        calls[:] = []
        self.assertEqual(x.value, x.initial_value)
        x.acquire(calls.append, 'x')
        self.assertEqual(x.value, 1)
        x.acquire(calls.append, 'y')
        self.assertEqual(x.value, 0)
        x.release()
        self.assertEqual(x.value, 1)
        x.release()
        self.assertEqual(x.value, 2)
        x.release()
        self.assertEqual(x.value, 2)
开发者ID:1995rishi,项目名称:flaskmap,代码行数:38,代码来源:test_semaphore.py


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