From cf21c0e0883358a4014d13b19927656b604c1a29 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Mon, 22 May 2017 19:17:34 +0200 Subject: [PATCH] [qa] attempt to fix #58. --- bonobo/execution/base.py | 7 ++++++- bonobo/execution/plugin.py | 19 +++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bonobo/execution/base.py b/bonobo/execution/base.py index d500e28..cefde32 100644 --- a/bonobo/execution/base.py +++ b/bonobo/execution/base.py @@ -8,6 +8,12 @@ from bonobo.plugins import get_enhancers from bonobo.util.errors import print_error from bonobo.util.objects import Wrapper, get_name +@contextmanager +def recoverable(error_handler): + try: + yield + except Exception as exc: # pylint: disable=broad-except + error_handler(exc, traceback.format_exc()) @contextmanager def unrecoverable(error_handler): @@ -17,7 +23,6 @@ def unrecoverable(error_handler): error_handler(exc, traceback.format_exc()) raise # raise unrecoverableerror from x ? - class LoopingExecutionContext(Wrapper): alive = True PERIOD = 0.25 diff --git a/bonobo/execution/plugin.py b/bonobo/execution/plugin.py index db5c0db..d928f4a 100644 --- a/bonobo/execution/plugin.py +++ b/bonobo/execution/plugin.py @@ -1,6 +1,4 @@ -import traceback - -from bonobo.execution.base import LoopingExecutionContext +from bonobo.execution.base import LoopingExecutionContext, recoverable class PluginExecutionContext(LoopingExecutionContext): @@ -14,21 +12,14 @@ class PluginExecutionContext(LoopingExecutionContext): def start(self): super().start() - try: + with recoverable(self.handle_error): self.wrapped.initialize() - except Exception as exc: # pylint: disable=broad-except - self.handle_error(exc, traceback.format_exc()) def shutdown(self): - try: + with recoverable(self.handle_error): self.wrapped.finalize() - except Exception as exc: # pylint: disable=broad-except - self.handle_error(exc, traceback.format_exc()) - finally: - self.alive = False + self.alive = False def step(self): - try: + with recoverable(self.handle_error): self.wrapped.run() - except Exception as exc: # pylint: disable=broad-except - self.handle_error(exc, traceback.format_exc())