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