test / src /storage /state.py
Akcom's picture
Some improvements
bfa18a9
raw
history blame contribute delete
921 Bytes
import time
from src.utils.singleton import Singleton
from src.modules.logger import logger as Logger
class State:
__metaclass__ = Singleton
def __init__(self):
# Common
self._lock = False
self._time_start = None
# Prediction
self._current_image = None
def _check_lock_assert(self):
if self._lock:
raise Exception('State locked')
# State begin - end
def begin(self):
self._check_lock_assert()
self._lock = True
self._time_start = time.time()
Logger.info(f"Started at: {self._time_start}")
def end(self):
self._lock = False
Logger.info(f"Stopped at: {time.time()}")
def set_current_image(self, image):
Logger.info(f"Set current image: {image}")
self._current_image = image
def get_current_image(self):
return self._current_image
state = State()