Exemple #1
0
        def run_callback():
            with kiwipy.capture_exceptions(kiwi_future):
                result = callback(*args, **kwargs)
                while concurrent.is_future(result):
                    result = yield result

                kiwi_future.set_result(result)
Exemple #2
0
 def on_created(_):
     with kiwipy.capture_exceptions(execute_future):
         pid = create_future.result()
         continue_future = self.continue_process(pid,
                                                 nowait=nowait,
                                                 no_reply=no_reply)
         kiwipy.chain(continue_future, execute_future)
Exemple #3
0
        async def run_callback():
            with kiwipy.capture_exceptions(kiwi_future):
                result = callback(*args, **kwargs)
                while asyncio.isfuture(result):
                    result = await result

                kiwi_future.set_result(result)
Exemple #4
0
    def test_capture_exceptions(self):
        future = kiwipy.Future()

        exception = RuntimeError()
        with kiwipy.capture_exceptions(future):
            raise exception

        self.assertIs(exception, future.exception())
Exemple #5
0
    def run(self, *args, **kwargs):
        if self.done():
            raise InvalidStateError("Action has already been ran")

        try:
            with kiwipy.capture_exceptions(self):
                self.set_result(self._action(*args, **kwargs))
        finally:
            self._action = None
Exemple #6
0
 def unwrap(fut):
     if fut.cancelled():
         unwrapping.cancel()
     else:
         with kiwipy.capture_exceptions(unwrapping):
             result = fut.result()
             if isinstance(result, kiwipy.Future):
                 result.add_done_callback(unwrap)
             else:
                 unwrapping.set_result(result)
Exemple #7
0
 def on_done(_plum_future):
     with kiwipy.capture_exceptions(kiwi_future):
         if plum_future.cancelled():
             kiwi_future.cancel()
         else:
             result = plum_future.result()
             # Did we get another future?  In which case convert it too
             if concurrent.is_future(result):
                 result = plum_to_kiwi_future(result)
             kiwi_future.set_result(result)
Exemple #8
0
    def done(done_future):
        if done_future.cancelled():
            tornado_future.cancel()

        with kiwipy.capture_exceptions(tornado_future):
            result = done_future.result()
            if isinstance(result, kiwipy.Future):
                result = kiwi_to_tornado_future(result, loop)

            tornado_future.set_result(result)
Exemple #9
0
    def run(self, *args, **kwargs):
        """
        Runt he action
        :param args: the positional arguments to the action
        :param kwargs: the keyword arguments to the action
        """
        if self.done():
            raise InvalidStateError("Action has already been ran")

        try:
            with kiwipy.capture_exceptions(self):
                self.set_result(self._action(*args, **kwargs))
        finally:
            self._action = None
Exemple #10
0
 def run_task():
     with kiwipy.capture_exceptions(future):
         future.set_result((yield coro()))
Exemple #11
0
 async def run_task():
     with kiwipy.capture_exceptions(future):
         res = await coro()
         future.set_result(res)