diff options
author | Théo de la Hogue | 2024-01-16 15:37:11 +0100 |
---|---|---|
committer | Théo de la Hogue | 2024-01-16 15:37:11 +0100 |
commit | f46c1f9e8268d87ae497fa8110ecebf517ba5645 (patch) | |
tree | a294417e2dd4ef92488663197067ff5b611bcf78 /src | |
parent | 53ee1a9a6e7ddc1b34fbaa8b0cf2e9936eebcf0d (diff) | |
download | argaze-f46c1f9e8268d87ae497fa8110ecebf517ba5645.zip argaze-f46c1f9e8268d87ae497fa8110ecebf517ba5645.tar.gz argaze-f46c1f9e8268d87ae497fa8110ecebf517ba5645.tar.bz2 argaze-f46c1f9e8268d87ae497fa8110ecebf517ba5645.tar.xz |
Adding more timestamp support and token support to SharedObject class.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/DataStructures.py | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index cf5bc3a..6e058e8 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -107,6 +107,7 @@ class SharedObject(): def __init__(self): self._lock = threading.Lock() self._timestamp = math.nan + self._token = None def acquire(self): self._lock.acquire() @@ -121,13 +122,54 @@ class SharedObject(): def timestamp(self) -> int|float: """Get timestamp""" - return self._timestamp + self._lock.acquire() + timestamp = self._timestamp + self._lock.release() + + return timestamp @timestamp.setter def timestamp(self, timestamp: int|float): """Set timestamp""" + self._lock.acquire() self._timestamp = timestamp + self._lock.release() + + def untimestamp(self): + """Reset timestamp""" + + self._lock.acquire() + self._timestamp = math.nan + self._lock.release() + + @property + def timestamped(self) -> bool: + """Is the object timestamped?""" + + self._lock.acquire() + timestamped = not math.isnan(self._timestamp) + self._lock.release() + + return timestamped + + @property + def token(self) -> any: + """Get token""" + + self._lock.acquire() + token = self._token + self._lock.release() + + return token + + @token.setter + def token(self, token: any): + """Set token""" + + self._lock.acquire() + self._token = token + self._lock.release() class TimeStampedBuffer(collections.OrderedDict): """Ordered dictionary to handle timestamped data. |