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


Python stack_context.ExceptionStackContext方法代碼示例

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


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

示例1: test_streaming_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_streaming_stack_context(self):
        chunks = []
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            return True

        def streaming_cb(chunk):
            chunks.append(chunk)
            if chunk == b'qwer':
                1 / 0

        with ExceptionStackContext(error_handler):
            self.fetch('/chunk', streaming_callback=streaming_cb)

        self.assertEqual(chunks, [b'asdf', b'qwer'])
        self.assertEqual(1, len(exc_info))
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:httpclient_test.py

示例2: test_streaming_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_streaming_stack_context(self):
        chunks = []
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            return True

        def streaming_cb(chunk):
            chunks.append(chunk)
            if chunk == b'qwer':
                1 / 0

        with ignore_deprecation():
            with ExceptionStackContext(error_handler):
                self.fetch('/chunk', streaming_callback=streaming_cb)

        self.assertEqual(chunks, [b'asdf', b'qwer'])
        self.assertEqual(1, len(exc_info))
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:httpclient_test.py

示例3: test_header_callback_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_header_callback_stack_context(self):
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            return True

        def header_callback(header_line):
            if header_line.lower().startswith('content-type:'):
                1 / 0

        with ignore_deprecation():
            with ExceptionStackContext(error_handler):
                self.fetch('/chunk', header_callback=header_callback)
        self.assertEqual(len(exc_info), 1)
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:18,代碼來源:httpclient_test.py

示例4: test_prepare_curl_callback_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_prepare_curl_callback_stack_context(self):
        exc_info = []
        error_event = Event()

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            error_event.set()
            return True

        with ignore_deprecation():
            with ExceptionStackContext(error_handler):
                request = HTTPRequest(self.get_url('/custom_reason'),
                                      prepare_curl_callback=lambda curl: 1 / 0)
        yield [error_event.wait(), self.http_client.fetch(request)]
        self.assertEqual(1, len(exc_info))
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:18,代碼來源:curl_httpclient_test.py

示例5: handle_request

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def handle_request(self, request, callback_clear_active, callback):
        """
        Create an HTTP2Stream object for the current request.
        :param request: client request
        :type request: HTTPRequest
        :param callback_clear_active: function executed when the request
                                      finishes, removes the current stream
                                      from the list of active streams.
        :param callback: function executed when the request finishes
        """
        stream = self.stream_cls(
            self.connection, request, callback_clear_active, callback,
            self.io_loop
        )

        with stack_context.ExceptionStackContext(stream.handle_exception):
            stream.begin_request() 
開發者ID:vladmunteanu,項目名稱:th2c,代碼行數:19,代碼來源:client.py

示例6: make_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def make_context(self):
        return stack_context.ExceptionStackContext(self.__handle_exception) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:stack_context_benchmark.py

示例7: _auth_return_future

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def _auth_return_future(f):
    """Similar to tornado.concurrent.return_future, but uses the auth
    module's legacy callback interface.

    Note that when using this decorator the ``callback`` parameter
    inside the function will actually be a future.
    """
    replacer = ArgReplacer(f, 'callback')

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        future = TracebackFuture()
        callback, args, kwargs = replacer.replace(future, args, kwargs)
        if callback is not None:
            future.add_done_callback(
                functools.partial(_auth_future_to_callback, callback))

        def handle_exception(typ, value, tb):
            if future.done():
                return False
            else:
                future.set_exc_info((typ, value, tb))
                return True
        with ExceptionStackContext(handle_exception):
            f(*args, **kwargs)
        return future
    return wrapper 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:29,代碼來源:auth.py

示例8: Task

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def Task(func, *args, **kwargs):
    """Adapts a callback-based asynchronous function for use in coroutines.

    Takes a function (and optional additional arguments) and runs it with
    those arguments plus a ``callback`` keyword argument.  The argument passed
    to the callback is returned as the result of the yield expression.

    .. versionchanged:: 4.0
       ``gen.Task`` is now a function that returns a `.Future`, instead of
       a subclass of `YieldPoint`.  It still behaves the same way when
       yielded.
    """
    future = Future()

    def handle_exception(typ, value, tb):
        if future.done():
            return False
        future.set_exc_info((typ, value, tb))
        return True

    def set_result(result):
        if future.done():
            return
        future.set_result(result)
    with stack_context.ExceptionStackContext(handle_exception):
        func(*args, callback=_argument_adapter(set_result), **kwargs)
    return future 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:29,代碼來源:gen.py

示例9: test_bad_host

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_bad_host(self):
        def handler(exc_typ, exc_val, exc_tb):
            self.stop(exc_val)
            return True  # Halt propagation.

        with ExceptionStackContext(handler):
            self.resolver.resolve('an invalid domain', 80, callback=self.stop)

        result = self.wait()
        self.assertIsInstance(result, Exception) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:12,代碼來源:netutil_test.py

示例10: test_header_callback_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_header_callback_stack_context(self):
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            return True

        def header_callback(header_line):
            if header_line.lower().startswith('content-type:'):
                1 / 0

        with ExceptionStackContext(error_handler):
            self.fetch('/chunk', header_callback=header_callback)
        self.assertEqual(len(exc_info), 1)
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:17,代碼來源:httpclient_test.py

示例11: test_prepare_curl_callback_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_prepare_curl_callback_stack_context(self):
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            self.stop()
            return True

        with ExceptionStackContext(error_handler):
            request = HTTPRequest(self.get_url('/'),
                                  prepare_curl_callback=lambda curl: 1 / 0)
        self.http_client.fetch(request, callback=self.stop)
        self.wait()
        self.assertEqual(1, len(exc_info))
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:17,代碼來源:curl_httpclient_test.py

示例12: test_add_future_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_add_future_stack_context(self):
        ready = threading.Event()

        def task():
            # we must wait for the ioloop callback to be scheduled before
            # the task completes to ensure that add_future adds the callback
            # asynchronously (which is the scenario in which capturing
            # the stack_context matters)
            ready.wait(1)
            assert ready.isSet(), "timed out"
            raise Exception("worker")

        def callback(future):
            self.future = future
            raise Exception("callback")

        def handle_exception(typ, value, traceback):
            self.exception = value
            self.stop()
            return True

        # stack_context propagates to the ioloop callback, but the worker
        # task just has its exceptions caught and saved in the Future.
        with futures.ThreadPoolExecutor(1) as pool:
            with ExceptionStackContext(handle_exception):
                self.io_loop.add_future(pool.submit(task), callback)
            ready.set()
        self.wait()

        self.assertEqual(self.exception.args[0], "callback")
        self.assertEqual(self.future.exception().args[0], "worker") 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:33,代碼來源:ioloop_test.py

示例13: run

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def run(self, result=None):
        with ExceptionStackContext(self._handle_exception):
            super(AsyncTestCase, self).run(result)
        # As a last resort, if an exception escaped super.run() and wasn't
        # re-raised in tearDown, raise it here.  This will cause the
        # unittest run to fail messily, but that's better than silently
        # ignoring an error.
        self.__rethrow() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:testing.py

示例14: test_header_callback_stack_context

# 需要導入模塊: from tornado import stack_context [as 別名]
# 或者: from tornado.stack_context import ExceptionStackContext [as 別名]
def test_header_callback_stack_context(self):
        exc_info = []

        def error_handler(typ, value, tb):
            exc_info.append((typ, value, tb))
            return True

        def header_callback(header_line):
            if header_line.startswith('Content-Type:'):
                1 / 0

        with ExceptionStackContext(error_handler):
            self.fetch('/chunk', header_callback=header_callback)
        self.assertEqual(len(exc_info), 1)
        self.assertIs(exc_info[0][0], ZeroDivisionError) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:17,代碼來源:httpclient_test.py


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