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