diff options
author | Théo de la Hogue | 2024-06-19 18:30:01 +0200 |
---|---|---|
committer | Théo de la Hogue | 2024-06-19 18:30:01 +0200 |
commit | 2b8cefb167d93c3c89dafc14170184bf63473d6f (patch) | |
tree | 3f459c950611484cf241cd6e727c0e3db913dd6c | |
parent | 71029e689c116af128ef016e513fd68614e85646 (diff) | |
download | argaze-2b8cefb167d93c3c89dafc14170184bf63473d6f.zip argaze-2b8cefb167d93c3c89dafc14170184bf63473d6f.tar.gz argaze-2b8cefb167d93c3c89dafc14170184bf63473d6f.tar.bz2 argaze-2b8cefb167d93c3c89dafc14170184bf63473d6f.tar.xz |
defining busy state for SharedObject. Defining SharedObjectBusy exception. Raising this exception when trying to get image from a busy shared object.
-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') |