def run(self): self.start_all_controllers() self.daemon_startup_time = timeit.default_timer() - self.startup_timer self.logger.info("Mycodo daemon v{ver} started in {time:.3f}" " seconds".format(ver=MYCODO_VERSION, time=self.daemon_startup_time)) self.startup_stats() try: # loop until daemon is instructed to shut down while self.daemon_run: now = time.time() # Log ram usage every 5 days if now > self.timer_ram_use: self.timer_ram_use = now + 432000 self.log_ram_usage() # Capture time-lapse image (if enabled) self.check_all_timelapses(now) # Generate output usage report (if enabled) if (self.relay_usage_report_gen and now > self.relay_usage_report_next_gen): generate_relay_usage_report() self.refresh_daemon_misc_settings() # Update timer # Collect and send anonymous statistics (if enabled) if (not self.opt_out_statistics and now > self.timer_stats): self.timer_stats = self.timer_stats + STATS_INTERVAL self.send_stats() # Check if running the latest version (if enabled) if now > self.timer_upgrade: self.timer_upgrade = self.timer_upgrade + UPGRADE_CHECK_INTERVAL if self.enable_upgrade_check: self.check_mycodo_upgrade_exists(now) time.sleep(0.25) except Exception as except_msg: self.logger.exception( "Unexpected error: {msg}".format(msg=except_msg)) raise # If the daemon errors or finishes, shut it down finally: self.logger.debug("Stopping all running controllers") self.stop_all_controllers() self.logger.info("Mycodo terminated in {:.3f} seconds\n\n".format( timeit.default_timer() - self.thread_shutdown_timer)) self.terminated = True # Wait for the client to receive the response before it disconnects time.sleep(1)
def run(self): self.start_all_controllers() self.daemon_startup_time = timeit.default_timer() - self.startup_timer self.logger.info("Mycodo daemon v{ver} started in {time:.3f}" " seconds".format(ver=MYCODO_VERSION, time=self.daemon_startup_time)) self.startup_stats() try: # loop until daemon is instructed to shut down while self.daemon_run: now = time.time() # Capture time-lapse image try: for each_camera in self.camera: self.timelapse_check(each_camera, now) except Exception: self.logger.exception("Timelapse ERROR") # Generate relay usage report if (self.relay_usage_report_gen and now > self.relay_usage_report_next_gen): try: generate_relay_usage_report() self.refresh_daemon_misc_settings() except Exception: self.logger.exception( "Relay Usage Report Generation ERROR") # Log ram usage every 24 hours if now > self.timer_ram_use: try: self.timer_ram_use = now + 86400 ram_mb = resource.getrusage( resource.RUSAGE_SELF).ru_maxrss / float(1000) self.logger.info( "{ram} MB ram in use".format(ram=ram_mb)) except Exception: self.logger.exception("Free Ram ERROR") # collect and send anonymous statistics if (not self.opt_out_statistics and now > self.timer_stats): try: self.timer_stats = self.timer_stats + STATS_INTERVAL self.send_stats() except Exception: self.logger.exception("Stats ERROR") time.sleep(0.25) GPIO.cleanup() except Exception as except_msg: self.logger.exception("Unexpected error: {}: {}".format( sys.exc_info()[0], except_msg)) raise # If the daemon errors or finishes, shut it down finally: self.logger.debug("Stopping all running controllers") self.stop_all_controllers() self.logger.info("Mycodo terminated in {:.3f} seconds\n\n".format( timeit.default_timer() - self.thread_shutdown_timer)) self.terminated = True # Wait for the client to receive the response before it disconnects time.sleep(0.25)