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


Python gen.TimeoutError方法代码示例

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


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

示例1: test_garbage_collection

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

        future = sem.acquire()
        self.assertEqual(102, len(sem._waiters))

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

        # Final waiter is still active.
        self.assertFalse(future.done())
        sem.release()
        self.assertTrue(future.done())

        # Prevent "Future exception was never retrieved" messages.
        for future in futures:
            self.assertRaises(TimeoutError, future.result) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:22,代码来源:locks_test.py

示例2: put

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def put(
        self, item: _T, timeout: Union[float, datetime.timedelta] = None
    ) -> "Future[None]":
        """Put an item into the queue, perhaps waiting until there is room.

        Returns a Future, which raises `tornado.util.TimeoutError` after a
        timeout.

        ``timeout`` may be a number denoting a time (on the same
        scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.
        """
        future = Future()  # type: Future[None]
        try:
            self.put_nowait(item)
        except QueueFull:
            self._putters.append((item, future))
            _set_timeout(future, timeout)
        else:
            future.set_result(None)
        return future 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:24,代码来源:queues.py

示例3: test_garbage_collection

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def test_garbage_collection(self):
        # Test that timed-out waiters are occasionally cleaned from the queue.
        sem = locks.Semaphore(value=0)
        futures = [
            asyncio.ensure_future(sem.acquire(timedelta(seconds=0.01)))
            for _ in range(101)
        ]

        future = asyncio.ensure_future(sem.acquire())
        self.assertEqual(102, len(sem._waiters))

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

        # Final waiter is still active.
        self.assertFalse(future.done())
        sem.release()
        self.assertTrue(future.done())

        # Prevent "Future exception was never retrieved" messages.
        for future in futures:
            self.assertRaises(TimeoutError, future.result) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:locks_test.py

示例4: test_put_clears_timed_out_getters

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

示例5: put

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def put(self, item, timeout=None):
        """Put an item into the queue, perhaps waiting until there is room.

        Returns a Future, which raises `tornado.util.TimeoutError` after a
        timeout.

        ``timeout`` may be a number denoting a time (on the same
        scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.
        """
        future = Future()
        try:
            self.put_nowait(item)
        except QueueFull:
            self._putters.append((item, future))
            _set_timeout(future, timeout)
        else:
            future.set_result(None)
        return future 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:queues.py

示例6: get

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def get(self, timeout=None):
        """Remove and return an item from the queue.

        Returns a Future which resolves once an item is available, or raises
        `tornado.util.TimeoutError` after a timeout.

        ``timeout`` may be a number denoting a time (on the same
        scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.
        """
        future = Future()
        try:
            future.set_result(self.get_nowait())
        except QueueEmpty:
            self._getters.append(future)
            _set_timeout(future, timeout)
        return future 
开发者ID:tp4a,项目名称:teleport,代码行数:20,代码来源:queues.py

示例7: wait

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def wait(self, timeout=None):
        """Block until the internal flag is true.

        Returns a Future, which raises `tornado.util.TimeoutError` after a
        timeout.
        """
        fut = Future()
        if self._value:
            fut.set_result(None)
            return fut
        self._waiters.add(fut)
        fut.add_done_callback(lambda fut: self._waiters.remove(fut))
        if timeout is None:
            return fut
        else:
            timeout_fut = gen.with_timeout(timeout, fut, quiet_exceptions=(CancelledError,))
            # This is a slightly clumsy workaround for the fact that
            # gen.with_timeout doesn't cancel its futures. Cancelling
            # fut will remove it from the waiters list.
            timeout_fut.add_done_callback(lambda tf: fut.cancel() if not fut.done() else None)
            return timeout_fut 
开发者ID:tp4a,项目名称:teleport,代码行数:23,代码来源:locks.py

示例8: acquire

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def acquire(self, timeout=None):
        """Decrement the counter. Returns a Future.

        Block if the counter is zero and wait for a `.release`. The Future
        raises `.TimeoutError` after the deadline.
        """
        waiter = Future()
        if self._value > 0:
            self._value -= 1
            waiter.set_result(_ReleasingContextManager(self))
        else:
            self._waiters.append(waiter)
            if timeout:
                def on_timeout():
                    if not waiter.done():
                        waiter.set_exception(gen.TimeoutError())
                    self._garbage_collect()
                io_loop = ioloop.IOLoop.current()
                timeout_handle = io_loop.add_timeout(timeout, on_timeout)
                waiter.add_done_callback(
                    lambda _: io_loop.remove_timeout(timeout_handle))
        return waiter 
开发者ID:tp4a,项目名称:teleport,代码行数:24,代码来源:locks.py

示例9: _set_timeout

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def _set_timeout(future, timeout):
    if timeout:
        def on_timeout():
            future.set_exception(gen.TimeoutError())
        io_loop = ioloop.IOLoop.current()
        timeout_handle = io_loop.add_timeout(timeout, on_timeout)
        future.add_done_callback(
            lambda _: io_loop.remove_timeout(timeout_handle)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:queues.py

示例10: put

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def put(self, item, timeout=None):
        """将一个项目放入队列中, 可能需要等待直到队列中有空间.

        返回一个Future对象, 如果超时会抛出 `tornado.gen.TimeoutError` .
        """
        try:
            self.put_nowait(item)
        except QueueFull:
            future = Future()
            self._putters.append((item, future))
            _set_timeout(future, timeout)
            return future
        else:
            return gen._null_future 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:16,代码来源:queues.py

示例11: get

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def get(self, timeout=None):
        """从队列中删除并返回一个项目.

        返回一个Future对象, 当项目可用时resolve, 或者在超时后抛出
        `tornado.gen.TimeoutError` .
        """
        future = Future()
        try:
            future.set_result(self.get_nowait())
        except QueueEmpty:
            self._getters.append(future)
            _set_timeout(future, timeout)
        return future 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:queues.py

示例12: join

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def join(self, timeout=None):
        """阻塞(block)直到队列中的所有项目都处理完.

        返回一个Future对象, 超时后会抛出 `tornado.gen.TimeoutError` 异常.
        """
        return self._finished.wait(timeout) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:queues.py

示例13: wait

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def wait(self, timeout=None):
        """阻塞直到内部标识为true.

        返回一个Future对象, 在超时之后会抛出一个 `tornado.gen.TimeoutError`
        异常.
        """
        if timeout is None:
            return self._future
        else:
            return gen.with_timeout(timeout, self._future) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:locks.py

示例14: acquire

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def acquire(self, timeout=None):
        """尝试锁. 返回一个Future 对象.

        返回一个Future 对象, 在超时之后将抛出
        `tornado.gen.TimeoutError` .
        """
        return self._block.acquire(timeout) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:locks.py

示例15: test_timeout

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import TimeoutError [as 别名]
def test_timeout(self):
        with self.assertRaises(gen.TimeoutError):
            yield gen.with_timeout(datetime.timedelta(seconds=0.1),
                                   Future()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:gen_test.py


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