当前位置: 首页>>代码示例>>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;未经允许,请勿转载。