コード例 #1
0
 def __wrapper__(*args, **kwargs):
     _stack_context_handle_exception_partial = partial(
         _stack_context_handle_exception, handler=args[0])
     yield run_with_stack_context(
         stack_context.ExceptionStackContext(
             _stack_context_handle_exception_partial, delay_warning=True),
         lambda: method(*args, **kwargs))
コード例 #2
0
    def test_run_with_stack_context(self):
        @gen.coroutine
        def f1():
            self.assertEqual(self.active_contexts, ['c1'])
            yield run_with_stack_context(
                StackContext(functools.partial(self.context, 'c1')), f2)
            self.assertEqual(self.active_contexts, ['c1'])

        @gen.coroutine
        def f2():
            self.assertEqual(self.active_contexts, ['c1', 'c2'])
            yield gen.Task(self.io_loop.add_callback)
            self.assertEqual(self.active_contexts, ['c1', 'c2'])

        self.assertEqual(self.active_contexts, [])
        run_with_stack_context(
            StackContext(functools.partial(self.context, 'c1')), f1)
        self.assertEqual(self.active_contexts, [])
コード例 #3
0
    def test_run_with_stack_context(self):
        @gen.coroutine
        def f1():
            self.assertEqual(self.active_contexts, ['c1'])
            yield run_with_stack_context(
                StackContext(functools.partial(self.context, 'c2')),
                f2)
            self.assertEqual(self.active_contexts, ['c1'])

        @gen.coroutine
        def f2():
            self.assertEqual(self.active_contexts, ['c1', 'c2'])
            yield gen.Task(self.io_loop.add_callback)
            self.assertEqual(self.active_contexts, ['c1', 'c2'])

        self.assertEqual(self.active_contexts, [])
        run_with_stack_context(
            StackContext(functools.partial(self.context, 'c1')),
            f1)
        self.assertEqual(self.active_contexts, [])
コード例 #4
0
ファイル: context_manager.py プロジェクト: fcopello/barbante
    def run_with_new_context(func, tracer_id: str=None, endpoint: str=None, environment: str=None):
        """ Stacks a new context in the thread's current stack and then run the method ``work``.

        Does the same as ``new_session`` but in an uglier fashion. Use ``new_session`` if possible.

        :param func: a function (usually a partial function) with the work to be done.
        :param tracer_id: an optional tracer id used when logging
        :param endpoint: name of the endpoint that was requested
        """
        context = GlobalContextManager.prepare_context(tracer_id, endpoint, environment)
        stack_context = StackContext(partial(global_context_manager.push_context, context))
        return run_with_stack_context(stack_context, func)
コード例 #5
0
    def wrapper(self, *args, **kwargs):
        self._auto_finish = False
        self.token = yield stack_context.run_with_stack_context(
            stack_context.ExceptionStackContext(
                self._stack_context_handle_exception), self.validate_token)
        if not self.token:
            raise tornado.web.HTTPError(403)

        with stack_context.ExceptionStackContext(
                self._stack_context_handle_exception):

            result = method(self, *args, **kwargs)

            if isinstance(result, Future):

                def future_complete(f):
                    f.result()
                    if not self._finished:
                        self.finish()

                IOLoop.current().add_future(result, future_complete)
コード例 #6
0
 def f1():
     self.assertEqual(self.active_contexts, ['c1'])
     yield run_with_stack_context(
         StackContext(functools.partial(self.context, 'c2')),
         f2)
     self.assertEqual(self.active_contexts, ['c1'])
コード例 #7
0
 def f1():
     self.assertEqual(self.active_contexts, ['c1'])
     yield run_with_stack_context(
         StackContext(functools.partial(self.context, 'c2')), f2)
     self.assertEqual(self.active_contexts, ['c1'])
コード例 #8
0
 def _wrapper(*args, **kwargs):
     request_id = uuid.uuid4().hex
     yield run_with_stack_context(
         StackContext(lambda: RequestIDContext(request_id)),
         lambda: func(*args, **kwargs))
コード例 #9
0
ファイル: scope.py プロジェクト: FlorianLudwig/rueckenwind
 def run(self, target_coroutine):
     yield stack_context.run_with_stack_context(self(), target_coroutine)
コード例 #10
0
ファイル: scope.py プロジェクト: FlorianLudwig/rueckenwind
 def run(self, target_coroutine):
     yield stack_context.run_with_stack_context(self(), target_coroutine)