当前位置: 首页>>代码示例>>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;未经允许,请勿转载。