def register(self, var_name, var_value) : #, reload_interval = None, reload_func = None): RKLogger.debug(f'Register requested for {var_name}') if self._lock.acquire(True, 1): try: if var_name in self._variables: # Variable already exists return False elif var_value is None: # Variable value cannot be None return False else: self._variables[var_name] = dict() self._variables[var_name]['name'] = var_name self._variables[var_name]['value'] = var_value # self._variables[var_name]['reload_interval'] = reload_interval # self._variables[var_name]['reload_func'] = reload_func # self._variables[var_name]['last_reload'] = time.time() return True except: return False finally: self._lock.release() else: # failed to get lock return False
def get(self, var_name): RKLogger.debug(f'Get requested for {var_name}') if self._lock.acquire(True, 1): try: if var_name in self._variables: return self._variables[var_name]['value'] else: return None finally: self._lock.release() else: return None
def do_POST(self): if self.do_preprocess(): try: content_length = int(self.headers['Content-Length']) self.request.post_data = self.rfile.read(content_length) except Exception as e: self.send_error(500, str(e), traceback.format_exc()) return try: RKLogger.debug(f'Executing function {self.function_name}') self.function(self.request, self.response) RKLogger.debug(f'Completed function {self.function_name}') except Exception as e: self.send_error(500, str(e), traceback.format_exc())
def do_GET(self): if self.do_preprocess(): try: RKLogger.debug(f'Executing function {self.function_name}') self.function(self.globals, self.request, self.response) RKLogger.debug(f'Completed function {self.function_name}') except BrokenPipeError as bpe: RKLogger.exception(str(bpe)) except Exception as e: try: self.send_error(500, str(e), traceback.format_exc()) except: pass finally: pass
def update(self, var_name, var_value): RKLogger.debug(f'Update requested for {var_name}') if self._lock.acquire(True, 1): try: if not var_name in self._variables: return False elif var_name in self._variables and var_value is None: del self._variables[var_name] else: self._variables[var_name]['value'] = var_value self._variables[var_name]['last_reload'] = time.time() return True except: return False finally: self._lock.release() else: # failed to get lock return False
def log_response_text(self, format, *args): RKLogger.debug(format, *args)
def log_message(self, format, *args): RKLogger.debug(format, *args)