From 2b8cefb167d93c3c89dafc14170184bf63473d6f Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 19 Jun 2024 18:30:01 +0200 Subject: defining busy state for SharedObject. Defining SharedObjectBusy exception. Raising this exception when trying to get image from a busy shared object. --- src/argaze/DataFeatures.py | 24 ++++++++++++++++++++++-- 1 file 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') -- cgit v1.1