def Monitor(self): nextTime = datetime.now() nextTimeSystemInfo = datetime.now() debug('Monitoring sensors and os resources started') while self.continueMonitoring: try: if datetime.now() > nextTime: self.raspberryValue = None self.raspberryValue = {} refreshTime = int(time()) if datetime.now() > nextTimeSystemInfo: with self.systemMutex: if not self.retrievingSystemInfo: ThreadPool.Submit( self.MonitorSystemInformation()) nextTimeSystemInfo = datetime.now() + timedelta( seconds=5) self.MonitorSensors() self.MonitorBus() if self.onDataChanged != None: self.onDataChanged(self.raspberryValue) bResult = self.RemoveRefresh(refreshTime) if bResult == True and self.onSystemInfo != None: self.onSystemInfo() self.sensorsRefreshCount += 1 nextTime = datetime.now() + timedelta( seconds=REFRESH_FREQUENCY) sleep(REFRESH_FREQUENCY) except: exception("Monitoring sensors and os resources failed: " + str()) debug('Monitoring sensors and os resources Finished')
def ExecuteConfigCommand(config_id, parameters): debug('RaspiConfig::config') command = "sudo " + CUSTOM_CONFIG_SCRIPT + " " + str( config_id) + " " + str(parameters) (output, returnCode) = ServiceManager.ExecuteCommand(command) debug('ExecuteConfigCommand ' + str(config_id) + ' args: ' + str(parameters) + ' retCode: ' + str(returnCode) + ' output: ' + output) if "reboot required" in output: ThreadPool.Submit(RaspiConfig.RestartService) #del output return (returnCode, output)
def rotatorJson(): try: global lastRotate if (datetime.now() - lastRotate).total_seconds() < JSON_FILE_DUMP_TIME: return debug('rotatorJson called') lastRotate = datetime.now() ThreadPool.Submit(rotatorJsonMp) # p = Process(target=rotatorJsonMp, args=()) # p.start() # p.join() #no wait for process -> p.join() except: exception('rotatorJson exception')
def Destroy(self): info('Shutting down client') self.exiting = True self.sensorsClient.StopMonitoring() if hasattr(self, 'schedulerEngine'): self.schedulerEngine.stop() if hasattr(self, 'updater'): self.updater.stop() if hasattr(self, 'writerThread'): self.writerThread.stop() if hasattr(self, 'readerThread'): self.readerThread.stop() if hasattr(self, 'processorThread'): self.processorThread.stop() ThreadPool.Shutdown() self.Stop() info('Client shut down')
def Start(self): #thread = Thread(target = self.Test) #thread.start() ThreadPool.Submit(self.Test)
def BuildPT_PROCESS_LIST(self): ThreadPool.Submit(self.ThreadProcessManager)
def BuildPT_STARTUP_APPLICATIONS(self): ThreadPool.Submit(self.ThreadServiceManager)
def StartMonitoring(self): self.continueMonitoring = True #thread = Thread(target = self.Monitor) #thread.start() ThreadPool.Submit(self.Monitor)