当前位置: 首页>>代码示例>>Python>>正文


Python stack_context.StackContext方法代码示例

本文整理汇总了Python中tornado.stack_context.StackContext方法的典型用法代码示例。如果您正苦于以下问题:Python stack_context.StackContext方法的具体用法?Python stack_context.StackContext怎么用?Python stack_context.StackContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.stack_context的用法示例。


在下文中一共展示了stack_context.StackContext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pre_wrap_with_args

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_pre_wrap_with_args(self):
        # Same as test_pre_wrap, but the function takes arguments.
        # Implementation note: The function must not be wrapped in a
        # functools.partial until after it has been passed through
        # stack_context.wrap
        def f1(foo, bar):
            self.assertIn('c1', self.active_contexts)
            self.assertNotIn('c2', self.active_contexts)
            self.stop((foo, bar))

        with StackContext(functools.partial(self.context, 'c1')):
            wrapped = wrap(f1)

        with StackContext(functools.partial(self.context, 'c2')):
            self.add_callback(wrapped, 1, bar=2)

        result = self.wait()
        self.assertEqual(result, (1, 2)) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:20,代码来源:ioloop_test.py

示例2: test_pre_wrap

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_pre_wrap(self):
        # A pre-wrapped callback is run in the context in which it was
        # wrapped, not when it was added to the IOLoop.
        def f1():
            self.assertIn('c1', self.active_contexts)
            self.assertNotIn('c2', self.active_contexts)
            self.stop()

        with ignore_deprecation():
            with StackContext(functools.partial(self.context, 'c1')):
                wrapped = wrap(f1)

            with StackContext(functools.partial(self.context, 'c2')):
                self.add_callback(wrapped)

        self.wait() 
开发者ID:tp4a,项目名称:teleport,代码行数:18,代码来源:ioloop_test.py

示例3: test_pre_wrap_with_args

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_pre_wrap_with_args(self):
        # Same as test_pre_wrap, but the function takes arguments.
        # Implementation note: The function must not be wrapped in a
        # functools.partial until after it has been passed through
        # stack_context.wrap
        def f1(foo, bar):
            self.assertIn('c1', self.active_contexts)
            self.assertNotIn('c2', self.active_contexts)
            self.stop((foo, bar))

        with ignore_deprecation():
            with StackContext(functools.partial(self.context, 'c1')):
                wrapped = wrap(f1)

            with StackContext(functools.partial(self.context, 'c2')):
                self.add_callback(wrapped, 1, bar=2)

        result = self.wait()
        self.assertEqual(result, (1, 2)) 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:ioloop_test.py

示例4: test_exit_library_context

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_exit_library_context(self):
        def library_function(callback):
            # capture the caller's context before introducing our own
            callback = wrap(callback)
            with StackContext(functools.partial(self.context, 'library')):
                self.io_loop.add_callback(
                  functools.partial(library_inner_callback, callback))

        def library_inner_callback(callback):
            self.assertEqual(self.active_contexts[-2:],
                             ['application', 'library'])
            callback()

        def final_callback():
            # implementation detail:  the full context stack at this point
            # is ['application', 'library', 'application'].  The 'library'
            # context was not removed, but is no longer innermost so
            # the application context takes precedence.
            self.assertEqual(self.active_contexts[-1], 'application')
            self.stop()
        with StackContext(functools.partial(self.context, 'application')):
            library_function(final_callback)
        self.wait() 
开发者ID:omererdem,项目名称:honeything,代码行数:25,代码来源:stack_context_test.py

示例5: test_request_context_manager_backwards_compatible

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_request_context_manager_backwards_compatible(self):
        span = opentracing.tracer.start_span(operation_name='test')

        @gen.coroutine
        def check():
            assert get_current_span() == span

        # Bypass ScopeManager/span_in_stack_context() and use
        # RequestContextManager directly.
        def run_coroutine(span, coro):
            def mgr():
                return RequestContextManager(span)

            with stack_context.StackContext(mgr):
                return coro()

        yield run_coroutine(span, check) 
开发者ID:uber-common,项目名称:opentracing-python-instrumentation,代码行数:19,代码来源:test_tornado_request_context.py

示例6: make_context

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def make_context(self):
        return stack_context.StackContext(self.__context) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:stack_context_benchmark.py

示例7: function_with_stack_context

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def function_with_stack_context(self, callback):
        # Technically this function should stack_context.wrap its callback
        # upon entry.  However, it is very common for this step to be
        # omitted.
        def step2():
            self.assertEqual(self.named_contexts, ['a'])
            self.io_loop.add_callback(callback)

        with stack_context.StackContext(self.named_context('a')):
            self.io_loop.add_callback(step2) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:12,代码来源:gen_test.py

示例8: test_handle_callback_exception

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [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

示例9: test_pre_wrap

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def test_pre_wrap(self):
        # A pre-wrapped callback is run in the context in which it was
        # wrapped, not when it was added to the IOLoop.
        def f1():
            self.assertIn('c1', self.active_contexts)
            self.assertNotIn('c2', self.active_contexts)
            self.stop()

        with StackContext(functools.partial(self.context, 'c1')):
            wrapped = wrap(f1)

        with StackContext(functools.partial(self.context, 'c2')):
            self.add_callback(wrapped)

        self.wait() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:17,代码来源:ioloop_test.py

示例10: _execute

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def _execute(self, transforms, *args, **kwargs):
        current_context = {'request': self.request}

        with stack_context.StackContext(functools.partial(ThreadlocalLikeRequestContext, **current_context)):
            return super(_HandlerPatch, self)._execute(transforms, *args, **kwargs) 
开发者ID:mqingyn,项目名称:torngas,代码行数:7,代码来源:handler.py

示例11: run

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def run(self, result=None):
        with StackContext(self._stack_context):
            super(AsyncTestCase, self).run(result)
        # In case an exception escaped super.run or the StackContext caught
        # an exception when there wasn't a wait() to re-raise it, do so here.
        self.__rethrow() 
开发者ID:omererdem,项目名称:honeything,代码行数:8,代码来源:testing.py

示例12: wait

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def wait(self, condition=None, timeout=5):
        """Runs the IOLoop until stop is called or timeout has passed.

        In the event of a timeout, an exception will be thrown.

        If condition is not None, the IOLoop will be restarted after stop()
        until condition() returns true.
        """
        if not self.__stopped:
            if timeout:
                def timeout_func():
                    try:
                        raise self.failureException(
                          'Async operation timed out after %s seconds' %
                          timeout)
                    except Exception:
                        self.__failure = sys.exc_info()
                    self.stop()
                if self.__timeout is not None:
                    self.io_loop.remove_timeout(self.__timeout)
                self.__timeout = self.io_loop.add_timeout(datetime.timedelta(seconds=timeout), timeout_func)
            while True:
                self.__running = True
                with NullContext():
                    # Wipe out the StackContext that was established in
                    # self.run() so that all callbacks executed inside the
                    # IOLoop will re-run it.
                    self.io_loop.start()
                if (self.__failure is not None or
                    condition is None or condition()):
                    break
        assert self.__stopped
        self.__stopped = False
        self.__rethrow()
        result = self.__stop_args
        self.__stop_args = None
        return result 
开发者ID:omererdem,项目名称:honeything,代码行数:39,代码来源:testing.py

示例13: context

# 需要导入模块: from tornado import stack_context [as 别名]
# 或者: from tornado.stack_context import StackContext [as 别名]
def context(self, name):
        self.active_contexts.append(name)
        yield
        self.assertEqual(self.active_contexts.pop(), name)

    # Simulates the effect of an asynchronous library that uses its own
    # StackContext internally and then returns control to the application. 
开发者ID:omererdem,项目名称:honeything,代码行数:9,代码来源:stack_context_test.py


注:本文中的tornado.stack_context.StackContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。