diff options
-rw-r--r-- | src/argaze/DataFeatures.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py index da158be..946b289 100644 --- a/src/argaze/DataFeatures.py +++ b/src/argaze/DataFeatures.py @@ -616,6 +616,19 @@ class SharedObject(): self._lock = threading.Lock() + def busy(self) -> bool: + """Return lock state.""" + + return self._lock.locked() + +class SharedObjectBusy(Exception): + """ + Exception to raised when a shared object is locked. + """ + + def __init__(self, message): + super().__init__(message) + @timestamp class TimestampedException(Exception): """Enable timestamp management for exception.""" @@ -750,8 +763,7 @@ def PipelineStepAttributeSetter(method): except KeyError: - raise ( - PipelineStepLoadingFailed(f'Annotations are missing for {method.__name__}: {method.__annotations__}')) + raise (PipelineStepLoadingFailed(f'Annotations are missing for {method.__name__}: {method.__annotations__}')) logging.debug('%s@%s.setter', get_class_path(self), method.__name__) logging.debug('\t> set %s with %s', expected_value_type.__name__, new_value_type.__name__) @@ -813,6 +825,14 @@ def PipelineStepImage(method): def wrapper(self, **kwargs) -> numpy.array: """Wrap pipeline step image method.""" + # Check shared object instance + if issubclass(type(self), SharedObject): + + # Busy shared object can't return image + if self.busy(): + + raise SharedObjectBusy(f'Can\'t return image because {self.name} is busy.') + if kwargs: logging.debug('\t> using kwargs') |