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)
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)
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)
def test_capture_exceptions(self): future = kiwipy.Future() exception = RuntimeError() with kiwipy.capture_exceptions(future): raise exception self.assertIs(exception, future.exception())
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
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)
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)
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)
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
def run_task(): with kiwipy.capture_exceptions(future): future.set_result((yield coro()))
async def run_task(): with kiwipy.capture_exceptions(future): res = await coro() future.set_result(res)