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


Python queues.Queue方法代碼示例

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


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

示例1: test_repr_and_str

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_repr_and_str(self):
        q = queues.Queue(maxsize=1)
        self.assertIn(hex(id(q)), repr(q))
        self.assertNotIn(hex(id(q)), str(q))
        q.get()

        for q_str in repr(q), str(q):
            self.assertTrue(q_str.startswith('<Queue'))
            self.assertIn('maxsize=1', q_str)
            self.assertIn('getters[1]', q_str)
            self.assertNotIn('putters', q_str)
            self.assertNotIn('tasks', q_str)

        q.put(None)
        q.put(None)
        # Now the queue is full, this putter blocks.
        q.put(None)

        for q_str in repr(q), str(q):
            self.assertNotIn('getters', q_str)
            self.assertIn('putters[1]', q_str)
            self.assertIn('tasks=2', q_str) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:24,代碼來源:queues_test.py

示例2: test_maxsize

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_maxsize(self):
        self.assertRaises(TypeError, queues.Queue, maxsize=None)
        self.assertRaises(ValueError, queues.Queue, maxsize=-1)

        q = queues.Queue(maxsize=2)
        self.assertTrue(q.empty())
        self.assertFalse(q.full())
        self.assertEqual(2, q.maxsize)
        self.assertTrue(q.put(0).done())
        self.assertTrue(q.put(1).done())
        self.assertFalse(q.empty())
        self.assertTrue(q.full())
        put2 = q.put(2)
        self.assertFalse(put2.done())
        self.assertEqual(0, (yield q.get()))  # Make room.
        self.assertTrue(put2.done())
        self.assertFalse(q.empty())
        self.assertTrue(q.full()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:20,代碼來源:queues_test.py

示例3: test_producer_consumer

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_producer_consumer(self):
        q = queues.Queue(maxsize=3)
        history = []

        # We don't yield between get() and task_done(), so get() must wait for
        # the next tick. Otherwise we'd immediately call task_done and unblock
        # join() before q.put() resumes, and we'd only process the first four
        # items.
        @gen.coroutine
        def consumer():
            while True:
                history.append((yield q.get()))
                q.task_done()

        @gen.coroutine
        def producer():
            for item in range(10):
                yield q.put(item)

        consumer()
        yield producer()
        yield q.join()
        self.assertEqual(list(range(10)), history) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:25,代碼來源:queues_test.py

示例4: test_repr_and_str

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_repr_and_str(self):
        q = queues.Queue(maxsize=1)  # type: queues.Queue[None]
        self.assertIn(hex(id(q)), repr(q))
        self.assertNotIn(hex(id(q)), str(q))
        q.get()

        for q_str in repr(q), str(q):
            self.assertTrue(q_str.startswith("<Queue"))
            self.assertIn("maxsize=1", q_str)
            self.assertIn("getters[1]", q_str)
            self.assertNotIn("putters", q_str)
            self.assertNotIn("tasks", q_str)

        q.put(None)
        q.put(None)
        # Now the queue is full, this putter blocks.
        q.put(None)

        for q_str in repr(q), str(q):
            self.assertNotIn("getters", q_str)
            self.assertIn("putters[1]", q_str)
            self.assertIn("tasks=2", q_str) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:queues_test.py

示例5: test_maxsize

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_maxsize(self):
        self.assertRaises(TypeError, queues.Queue, maxsize=None)
        self.assertRaises(ValueError, queues.Queue, maxsize=-1)

        q = queues.Queue(maxsize=2)  # type: queues.Queue[int]
        self.assertTrue(q.empty())
        self.assertFalse(q.full())
        self.assertEqual(2, q.maxsize)
        self.assertTrue(q.put(0).done())
        self.assertTrue(q.put(1).done())
        self.assertFalse(q.empty())
        self.assertTrue(q.full())
        put2 = q.put(2)
        self.assertFalse(put2.done())
        self.assertEqual(0, (yield q.get()))  # Make room.
        self.assertTrue(put2.done())
        self.assertFalse(q.empty())
        self.assertTrue(q.full()) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:20,代碼來源:queues_test.py

示例6: test_put_clears_timed_out_getters

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_put_clears_timed_out_getters(self):
        q = queues.Queue()  # type: queues.Queue[int]
        getters = [
            asyncio.ensure_future(q.get(timedelta(seconds=0.01))) for _ in range(10)
        ]
        get = asyncio.ensure_future(q.get())
        q.get()
        self.assertEqual(12, len(q._getters))
        yield gen.sleep(0.02)
        self.assertEqual(12, len(q._getters))
        self.assertFalse(get.done())  # Final waiters still active.
        q.put(0)  # put() clears the waiters.
        self.assertEqual(1, len(q._getters))
        self.assertEqual(0, (yield get))
        for getter in getters:
            self.assertRaises(TimeoutError, getter.result) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:18,代碼來源:queues_test.py

示例7: test_float_maxsize

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_float_maxsize(self):
        # If a float is passed for maxsize, a reasonable limit should
        # be enforced, instead of being treated as unlimited.
        # It happens to be rounded up.
        # http://bugs.python.org/issue21723
        q = queues.Queue(maxsize=1.3)  # type: ignore
        self.assertTrue(q.empty())
        self.assertFalse(q.full())
        q.put_nowait(0)
        q.put_nowait(1)
        self.assertFalse(q.empty())
        self.assertTrue(q.full())
        self.assertRaises(queues.QueueFull, q.put_nowait, 2)
        self.assertEqual(0, q.get_nowait())
        self.assertFalse(q.empty())
        self.assertFalse(q.full())

        yield q.put(2)
        put = q.put(3)
        self.assertFalse(put.done())
        self.assertEqual(1, (yield q.get()))
        yield put
        self.assertTrue(q.full()) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:25,代碼來源:queues_test.py

示例8: test_producer_consumer

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_producer_consumer(self):
        q = queues.Queue(maxsize=3)  # type: queues.Queue[int]
        history = []

        # We don't yield between get() and task_done(), so get() must wait for
        # the next tick. Otherwise we'd immediately call task_done and unblock
        # join() before q.put() resumes, and we'd only process the first four
        # items.
        @gen.coroutine
        def consumer():
            while True:
                history.append((yield q.get()))
                q.task_done()

        @gen.coroutine
        def producer():
            for item in range(10):
                yield q.put(item)

        consumer()
        yield producer()
        yield q.join()
        self.assertEqual(list(range(10)), history) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:25,代碼來源:queues_test.py

示例9: setUp

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def setUp(self):
        self.tracer = MockTracer(TornadoScopeManager())
        self.queue = queues.Queue()
        self.loop = ioloop.IOLoop.current()
        self.server = Server(tracer=self.tracer, queue=self.queue) 
開發者ID:opentracing,項目名稱:opentracing-python,代碼行數:7,代碼來源:test_tornado.py

示例10: main

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def main():
    q = queues.Queue()
    start = time.time()
    fetching, fetched = set(), set()

    @gen.coroutine
    def fetch_url():
        current_url = yield q.get()
        try:
            if current_url in fetching:
                return

            print('fetching %s' % current_url)
            fetching.add(current_url)
            urls = yield get_links_from_url(current_url)
            fetched.add(current_url)

            for new_url in urls:
                # Only follow links beneath the base URL
                if new_url.startswith(base_url):
                    yield q.put(new_url)

        finally:
            q.task_done()

    @gen.coroutine
    def worker():
        while True:
            yield fetch_url()

    q.put(base_url)

    # Start workers, then wait for the work queue to be empty.
    for _ in range(concurrency):
        worker()
    yield q.join(timeout=timedelta(seconds=300))
    assert fetching == fetched
    print('Done in %d seconds, fetched %s URLs.' % (
        time.time() - start, len(fetched))) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:41,代碼來源:webspider.py

示例11: test_order

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_order(self):
        q = queues.Queue()
        for i in [1, 3, 2]:
            q.put_nowait(i)

        items = [q.get_nowait() for _ in range(3)]
        self.assertEqual([1, 3, 2], items) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:9,代碼來源:queues_test.py

示例12: test_blocking_get

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_blocking_get(self):
        q = queues.Queue()
        q.put_nowait(0)
        self.assertEqual(0, (yield q.get())) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:6,代碼來源:queues_test.py

示例13: test_nonblocking_get_exception

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_nonblocking_get_exception(self):
        q = queues.Queue()
        self.assertRaises(queues.QueueEmpty, q.get_nowait) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:5,代碼來源:queues_test.py

示例14: test_get_with_putters

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_get_with_putters(self):
        q = queues.Queue(1)
        q.put_nowait(0)
        put = q.put(1)
        self.assertEqual(0, (yield q.get()))
        self.assertIsNone((yield put)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:queues_test.py

示例15: test_blocking_get_wait

# 需要導入模塊: from tornado import queues [as 別名]
# 或者: from tornado.queues import Queue [as 別名]
def test_blocking_get_wait(self):
        q = queues.Queue()
        q.put(0)
        self.io_loop.call_later(0.01, q.put, 1)
        self.io_loop.call_later(0.02, q.put, 2)
        self.assertEqual(0, (yield q.get(timeout=timedelta(seconds=1))))
        self.assertEqual(1, (yield q.get(timeout=timedelta(seconds=1)))) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:9,代碼來源:queues_test.py


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