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


Python gen.BadYieldError方法代碼示例

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


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

示例1: _run_callback

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback):
        """Runs a callback with error handling.

        For use in subclasses.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen
                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, lambda f: f.result())
        except Exception:
            self.handle_callback_exception(callback) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:26,代碼來源:ioloop.py

示例2: _run_callback

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback):
        """Runs a callback with error handling.

        For use in subclasses.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen
                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, self._discard_future_result)
        except Exception:
            self.handle_callback_exception(callback) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:26,代碼來源:ioloop.py

示例3: test_bogus_yield

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield(self):
        @gen.engine
        def f():
            yield 42
        self.assertRaises(gen.BadYieldError, self.run_gen, f) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:7,代碼來源:gen_test.py

示例4: test_bogus_yield_tuple

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield_tuple(self):
        @gen.engine
        def f():
            yield (1, 2)
        self.assertRaises(gen.BadYieldError, self.run_gen, f) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:7,代碼來源:gen_test.py

示例5: test_yield_sem

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_yield_sem(self):
        # Ensure we catch a "with (yield sem)", which should be
        # "with (yield sem.acquire())".
        with self.assertRaises(gen.BadYieldError):
            with (yield locks.Semaphore()):
                pass 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:locks_test.py

示例6: test_yield_lock

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_yield_lock(self):
        # Ensure we catch a "with (yield lock)", which should be
        # "with (yield lock.acquire())".
        with self.assertRaises(gen.BadYieldError):
            with (yield locks.Lock()):
                pass 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:8,代碼來源:locks_test.py

示例7: _run_callback

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback: Callable[[], Any]) -> None:
        """Runs a callback with error handling.

        .. versionchanged:: 6.0

           CancelledErrors are no longer logged.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen

                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, self._discard_future_result)
        except asyncio.CancelledError:
            pass
        except Exception:
            app_log.error("Exception in callback %r", callback, exc_info=True) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:31,代碼來源:ioloop.py

示例8: test_bogus_yield

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield(self):
        @gen.coroutine
        def f():
            yield 42

        self.assertRaises(gen.BadYieldError, self.io_loop.run_sync, f) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:8,代碼來源:gen_test.py

示例9: test_bogus_yield_tuple

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield_tuple(self):
        @gen.coroutine
        def f():
            yield (1, 2)

        self.assertRaises(gen.BadYieldError, self.io_loop.run_sync, f) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:8,代碼來源:gen_test.py


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