コード例 #1
0
 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
コード例 #2
0
 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
コード例 #3
0
 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())
コード例 #4
0
 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
コード例 #5
0
 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
コード例 #6
0
 def log_response_text(self, format, *args):
     RKLogger.debug(format, *args)
コード例 #7
0
 def log_error(self, format, *args):
     RKLogger.exception(format, *args)
コード例 #8
0
 def log_message(self, format, *args):
     RKLogger.debug(format, *args)
コード例 #9
0
                           
    
    return RKHTTPRequestHandler

   
class RKHTTPServer(ThreadingMixIn, HTTPServer):
    pass
    

if __name__ == '__main__':
    tracemalloc.start()
    try:
        #gc.set_debug(gc.DEBUG_LEAK)
        ipaddr = socket.gethostname()
        port = 8282
        RKLogger.initialize('rkhttp', 'rkhttp.log', RKLogger.DEBUG)
        gl = RKHttpGlobals()
        server = RKHTTPServer((ipaddr, port), RKHandlerClassFactory(gl))
        print (f'listening on address {ipaddr} and port {port}')
        server.serve_forever()
    except Exception as e:
        print(e)
    finally:
        del(gl)
        del(server)
        gc.collect()
        trace_memory_leaks()