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


Python IOLoop.handle_callback_exception方法代碼示例

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


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

示例1: test_final_callback_stack_context

# 需要導入模塊: from tornado.ioloop import IOLoop [as 別名]
# 或者: from tornado.ioloop.IOLoop import handle_callback_exception [as 別名]
def test_final_callback_stack_context(self):
        # The final callback should be run outside of the httpclient's
        # stack_context.  We want to ensure that there is not stack_context
        # between the user's callback and the IOLoop, so monkey-patch
        # IOLoop.handle_callback_exception and disable the test harness's
        # context with a NullContext.
        # Note that this does not apply to secondary callbacks (header
        # and streaming_callback), as errors there must be seen as errors
        # by the http client so it can clean up the connection.
        exc_info = []

        def handle_callback_exception(callback):
            exc_info.append(sys.exc_info())
            self.stop()
        self.io_loop.handle_callback_exception = handle_callback_exception
        with NullContext():
            self.http_client.fetch(self.get_url('/hello'),
                                   lambda response: 1 / 0)
        self.wait()
        self.assertEqual(exc_info[0][0], ZeroDivisionError) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:22,代碼來源:httpclient_test.py

示例2: test_final_callback_stack_context

# 需要導入模塊: from tornado.ioloop import IOLoop [as 別名]
# 或者: from tornado.ioloop.IOLoop import handle_callback_exception [as 別名]
def test_final_callback_stack_context(self):
        # The final callback should be run outside of the httpclient's
        # stack_context.  We want to ensure that there is not stack_context
        # between the user's callback and the IOLoop, so monkey-patch
        # IOLoop.handle_callback_exception and disable the test harness's
        # context with a NullContext.
        # Note that this does not apply to secondary callbacks (header
        # and streaming_callback), as errors there must be seen as errors
        # by the http client so it can clean up the connection.
        exc_info = []

        def handle_callback_exception(callback):
            exc_info.append(sys.exc_info())
            self.stop()
        self.io_loop.handle_callback_exception = handle_callback_exception
        with NullContext():
            with ignore_deprecation():
                self.http_client.fetch(self.get_url('/hello'),
                                       lambda response: 1 / 0)
        self.wait()
        self.assertEqual(exc_info[0][0], ZeroDivisionError) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:23,代碼來源:httpclient_test.py

示例3: test_handle_callback_exception

# 需要導入模塊: from tornado.ioloop import IOLoop [as 別名]
# 或者: from tornado.ioloop.IOLoop import handle_callback_exception [as 別名]
def test_handle_callback_exception(self):
        # IOLoop.handle_callback_exception can be overridden to catch
        # exceptions in callbacks.
        def handle_callback_exception(callback):
            self.assertIs(sys.exc_info()[0], ZeroDivisionError)
            self.stop()
        self.io_loop.handle_callback_exception = handle_callback_exception
        with NullContext():
            # remove the test StackContext that would see this uncaught
            # exception as a test failure.
            self.io_loop.add_callback(lambda: 1 / 0)
        self.wait() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:14,代碼來源:ioloop_test.py


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