diff options
author | Théo de la Hogue | 2024-04-25 15:28:09 +0200 |
---|---|---|
committer | Théo de la Hogue | 2024-04-25 15:28:09 +0200 |
commit | c3da8e8bf35360377ef15568d1cbd75dc70ec016 (patch) | |
tree | bf08370f05c7290ceaa16ee0c765a69aa9ac6691 | |
parent | e827c11c910a2be15aa55e88023c0b3632b08ead (diff) | |
download | argaze-c3da8e8bf35360377ef15568d1cbd75dc70ec016.zip argaze-c3da8e8bf35360377ef15568d1cbd75dc70ec016.tar.gz argaze-c3da8e8bf35360377ef15568d1cbd75dc70ec016.tar.bz2 argaze-c3da8e8bf35360377ef15568d1cbd75dc70ec016.tar.xz |
Moving cacth_exceptions attributes into PipelineStepObject.
-rw-r--r-- | src/argaze/ArFeatures.py | 20 | ||||
-rw-r--r-- | src/argaze/DataFeatures.py | 22 |
2 files changed, 22 insertions, 20 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py index d20f359..c478207 100644 --- a/src/argaze/ArFeatures.py +++ b/src/argaze/ArFeatures.py @@ -1474,7 +1474,6 @@ class ArContext(DataFeatures.PipelineStepObject): # Init private attributes self.__pipeline = None - self.__catch_exceptions = True self.__exceptions = DataFeatures.TimestampedExceptions() # Init gaze position processing assessment @@ -1503,16 +1502,6 @@ class ArContext(DataFeatures.PipelineStepObject): self.__pipeline = pipeline - @property - def catch_exceptions(self) -> bool: - """Catch pipeline exception to display them instead of crashing execution.""" - return self.__catch_exceptions - - @catch_exceptions.setter - def catch_exceptions(self, catch_exceptions: bool): - - self.__catch_exceptions = catch_exceptions - def exceptions(self) -> DataFeatures.TimestampedExceptions: """Get exceptions list""" return self.__exceptions @@ -1523,7 +1512,6 @@ class ArContext(DataFeatures.PipelineStepObject): return { **DataFeatures.PipelineStepObject.as_dict(self), "pipeline": self.__pipeline, - "catch_exceptions": self.__catch_exceptions, "image_parameters": self._image_parameters } @@ -1561,12 +1549,12 @@ class ArContext(DataFeatures.PipelineStepObject): if x is None and y is None: # Edit empty gaze position - self.__pipeline.look(GazeFeatures.GazePosition(timestamp=timestamp), catch_exceptions=self.__catch_exceptions) + self.__pipeline.look(GazeFeatures.GazePosition(timestamp=timestamp)) else: # Edit gaze position - self.__pipeline.look(GazeFeatures.GazePosition((x, y), precision=precision, timestamp=timestamp), catch_exceptions=self.__catch_exceptions) + self.__pipeline.look(GazeFeatures.GazePosition((x, y), precision=precision, timestamp=timestamp)) #except DataFeatures.TimestampedException as e: @@ -1625,10 +1613,10 @@ class ArContext(DataFeatures.PipelineStepObject): logging.debug('\t> watch image (%i x %i)', width, height) - self.__pipeline.watch(DataFeatures.TimestampedImage(image, timestamp=timestamp), catch_exceptions=self.__catch_exceptions) + self.__pipeline.watch(DataFeatures.TimestampedImage(image, timestamp=timestamp)) # TODO: make this step optional - self.__pipeline.map(timestamp=timestamp, catch_exceptions=self.__catch_exceptions) + self.__pipeline.map(timestamp=timestamp) except DataFeatures.TimestampedException as e: diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py index 0791d5e..b4874d3 100644 --- a/src/argaze/DataFeatures.py +++ b/src/argaze/DataFeatures.py @@ -857,6 +857,7 @@ class PipelineStepObject(): self.__image_parameters = {} # Init protected attributes + self._catch_exceptions = False self._image_parameters = {} self._draw_parameters = {} @@ -941,6 +942,21 @@ class PipelineStepObject(): return self.__execution_times @property + def catch_exceptions(self) -> bool: + """Catch pipeline step method exception instead of crashing execution.""" + return self._catch_exceptions + + @catch_exceptions.setter + def catch_exceptions(self, catch_exceptions: bool): + + self._catch_exceptions = catch_exceptions + + # Propagate to children + for child in self.children(): + + child.catch_exceptions = self._catch_exceptions + + @property def image_parameters(self) -> dict: """image method parameters dictionary.""" return self._image_parameters @@ -1138,8 +1154,7 @@ def PipelineStepMethod(method): PipelineStepMethod must have a timestamp as first argument. """ - def wrapper(self, *args, timestamp: int | float = None, unwrap: bool = False, catch_exceptions: bool = True, - **kwargs): + def wrapper(self, *args, timestamp: int | float = None, unwrap: bool = False, **kwargs): """Wrap pipeline step method to measure execution time. Parameters: @@ -1148,7 +1163,6 @@ def PipelineStepMethod(method): timestamp: optional method call timestamp (unit doesn't matter) if first args parameter is not a TimestampedObject instance. unwrap: extra arguments used in wrapper function to call wrapped method directly. - catch_exceptions: extra arguments used in wrapper function to catch exception. """ if timestamp is None and len(args) > 0: @@ -1169,7 +1183,7 @@ def PipelineStepMethod(method): exception = None result = None - if not catch_exceptions: + if not self._catch_exceptions: # Execute wrapped method without catching exceptions result = method(self, *args, **kwargs) |