Пример #1
0
 def __write_data(self, data) -> None:
     self.__WRITE_LOCK.acquire()
     self.__data = data
     self.__modify_date = util.get_utcnow()
     util.dbg_prnt(
         f'[PssCache[{self.name}].__write_data] Stored {len(data)} bytes on {self.__modify_date}'
     )
     self.__WRITE_LOCK.release()
Пример #2
0
    def get_raw_data(self) -> str:
        util.dbg_prnt(f'+ PssCache[{self.name}].get_data()')
        if self.__get_is_data_outdated():
            util.dbg_prnt(f'[PssCache[{self.name}].get_data] Data is outdated')
            self.update_data()

        can_read = False
        while not can_read:
            can_read = not self.__get_write_requested()
            if not can_read:
                time.sleep(random.random())

        self.__add_reader()
        result = self.__read_data()
        self.__remove_reader()
        return result
Пример #3
0
 def update_data(self, old_data=None) -> bool:
     util.dbg_prnt(f'+ PssCache[{self.name}].update_data(old_data)')
     util.dbg_prnt(
         f'[PssCache[{self.name}].update_data] Fetch data from path: {self.__update_path}'
     )
     data = core.get_data_from_path(self.__update_path)
     util.dbg_prnt(
         f'[PssCache[{self.name}].update_data] Retrieved {len(data)} bytes')
     data_changed = data != old_data
     if data_changed:
         self.__request_write()
         can_write = False
         while not can_write:
             can_write = self.__get_reader_count() == 0
             if not can_write:
                 time.sleep(random.random())
         self.__write_data(data)
         self.__finish_write()
         return True
     return False