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


Python locks.Condition方法代码示例

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


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

示例1: test_notify_n_with_timeout

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_n_with_timeout(self):
        # Register callbacks 0, 1, 2, and 3. Callback 1 has a timeout.
        # Wait for that timeout to expire, then do notify(2) and make
        # sure everyone runs. Verifies that a timed-out callback does
        # not count against the 'n' argument to notify().
        c = locks.Condition()
        self.record_done(c.wait(), 0)
        self.record_done(c.wait(timedelta(seconds=0.01)), 1)
        self.record_done(c.wait(), 2)
        self.record_done(c.wait(), 3)

        # Wait for callback 1 to time out.
        yield gen.sleep(0.02)
        self.assertEqual(['timeout'], self.history)

        c.notify(2)
        yield gen.sleep(0.01)
        self.assertEqual(['timeout', 0, 2], self.history)
        self.assertEqual(['timeout', 0, 2], self.history)
        c.notify()
        self.assertEqual(['timeout', 0, 2, 3], self.history) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:23,代码来源:locks_test.py

示例2: test_garbage_collection

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_garbage_collection(self):
        # Test that timed-out waiters are occasionally cleaned from the queue.
        c = locks.Condition()
        for _ in range(101):
            c.wait(timedelta(seconds=0.01))

        future = c.wait()
        self.assertEqual(102, len(c._waiters))

        # Let first 101 waiters time out, triggering a collection.
        yield gen.sleep(0.02)
        self.assertEqual(1, len(c._waiters))

        # Final waiter is still active.
        self.assertFalse(future.done())
        c.notify()
        self.assertTrue(future.done()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:locks_test.py

示例3: test_future_close_callback

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_future_close_callback(self):
        # Regression test for interaction between the Future read interfaces
        # and IOStream._maybe_add_error_listener.
        rs, ws = yield self.make_iostream_pair()
        closed = [False]
        cond = Condition()

        def close_callback():
            closed[0] = True
            cond.notify()

        rs.set_close_callback(close_callback)
        try:
            ws.write(b"a")
            res = yield rs.read_bytes(1)
            self.assertEqual(res, b"a")
            self.assertFalse(closed[0])
            ws.close()
            yield cond.wait()
            self.assertTrue(closed[0])
        finally:
            rs.close()
            ws.close() 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:iostream_test.py

示例4: test_notify_n

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_n(self):
        c = locks.Condition()
        for i in range(6):
            self.record_done(c.wait(), i)

        c.notify(3)
        self.loop_briefly()

        # Callbacks execute in the order they were registered.
        self.assertEqual(list(range(3)), self.history)
        c.notify(1)
        self.loop_briefly()
        self.assertEqual(list(range(4)), self.history)
        c.notify(2)
        self.loop_briefly()
        self.assertEqual(list(range(6)), self.history) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:18,代码来源:locks_test.py

示例5: test_notify_n_with_timeout

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_n_with_timeout(self):
        # Register callbacks 0, 1, 2, and 3. Callback 1 has a timeout.
        # Wait for that timeout to expire, then do notify(2) and make
        # sure everyone runs. Verifies that a timed-out callback does
        # not count against the 'n' argument to notify().
        c = locks.Condition()
        self.record_done(c.wait(), 0)
        self.record_done(c.wait(timedelta(seconds=0.01)), 1)
        self.record_done(c.wait(), 2)
        self.record_done(c.wait(), 3)

        # Wait for callback 1 to time out.
        yield gen.sleep(0.02)
        self.assertEqual(["timeout"], self.history)

        c.notify(2)
        yield gen.sleep(0.01)
        self.assertEqual(["timeout", 0, 2], self.history)
        self.assertEqual(["timeout", 0, 2], self.history)
        c.notify()
        yield
        self.assertEqual(["timeout", 0, 2, 3], self.history) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:24,代码来源:locks_test.py

示例6: test_garbage_collection

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_garbage_collection(self):
        # Test that timed-out waiters are occasionally cleaned from the queue.
        c = locks.Condition()
        for _ in range(101):
            c.wait(timedelta(seconds=0.01))

        future = asyncio.ensure_future(c.wait())
        self.assertEqual(102, len(c._waiters))

        # Let first 101 waiters time out, triggering a collection.
        yield gen.sleep(0.02)
        self.assertEqual(1, len(c._waiters))

        # Final waiter is still active.
        self.assertFalse(future.done())
        c.notify()
        self.assertTrue(future.done()) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:locks_test.py

示例7: test_future_close_callback

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_future_close_callback(self):
        # Regression test for interaction between the Future read interfaces
        # and IOStream._maybe_add_error_listener.
        rs, ws = yield self.make_iostream_pair()
        closed = [False]
        cond = Condition()

        def close_callback():
            closed[0] = True
            cond.notify()
        rs.set_close_callback(close_callback)
        try:
            ws.write(b'a')
            res = yield rs.read_bytes(1)
            self.assertEqual(res, b'a')
            self.assertFalse(closed[0])
            ws.close()
            yield cond.wait()
            self.assertTrue(closed[0])
        finally:
            rs.close()
            ws.close() 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:iostream_test.py

示例8: test_notify_n_with_timeout

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_n_with_timeout(self):
        # Register callbacks 0, 1, 2, and 3. Callback 1 has a timeout.
        # Wait for that timeout to expire, then do notify(2) and make
        # sure everyone runs. Verifies that a timed-out callback does
        # not count against the 'n' argument to notify().
        c = locks.Condition()
        self.record_done(c.wait(), 0)
        self.record_done(c.wait(timedelta(seconds=0.01)), 1)
        self.record_done(c.wait(), 2)
        self.record_done(c.wait(), 3)

        # Wait for callback 1 to time out.
        yield gen.sleep(0.02)
        self.assertEqual(['timeout'], self.history)

        c.notify(2)
        yield gen.sleep(0.01)
        self.assertEqual(['timeout', 0, 2], self.history)
        self.assertEqual(['timeout', 0, 2], self.history)
        c.notify()
        yield
        self.assertEqual(['timeout', 0, 2, 3], self.history) 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:locks_test.py

示例9: __init__

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def __init__(self):
        super(Condition, self).__init__()
        self.io_loop = ioloop.IOLoop.current() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:locks.py

示例10: record_done

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def record_done(self, future, key):
        """Record the resolution of a Future returned by Condition.wait."""
        def callback(_):
            if not future.result():
                # wait() resolved to False, meaning it timed out.
                self.history.append('timeout')
            else:
                self.history.append(key)
        future.add_done_callback(callback) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:11,代码来源:locks_test.py

示例11: test_repr

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_repr(self):
        c = locks.Condition()
        self.assertIn('Condition', repr(c))
        self.assertNotIn('waiters', repr(c))
        c.wait()
        self.assertIn('waiters', repr(c)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例12: test_notify

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify(self):
        c = locks.Condition()
        self.io_loop.call_later(0.01, c.notify)
        yield c.wait() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:locks_test.py

示例13: test_notify_1

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_1(self):
        c = locks.Condition()
        self.record_done(c.wait(), 'wait1')
        self.record_done(c.wait(), 'wait2')
        c.notify(1)
        self.history.append('notify1')
        c.notify(1)
        self.history.append('notify2')
        self.assertEqual(['wait1', 'notify1', 'wait2', 'notify2'],
                         self.history) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:locks_test.py

示例14: test_notify_all

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_notify_all(self):
        c = locks.Condition()
        for i in range(4):
            self.record_done(c.wait(), i)

        c.notify_all()
        self.history.append('notify_all')

        # Callbacks execute in the order they were registered.
        self.assertEqual(
            list(range(4)) + ['notify_all'],
            self.history) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:locks_test.py

示例15: test_wait_timeout

# 需要导入模块: from tornado import locks [as 别名]
# 或者: from tornado.locks import Condition [as 别名]
def test_wait_timeout(self):
        c = locks.Condition()
        wait = c.wait(timedelta(seconds=0.01))
        self.io_loop.call_later(0.02, c.notify)  # Too late.
        yield gen.sleep(0.03)
        self.assertFalse((yield wait)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py


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