def run(self): """Thread main loop""" while (app.running): time.sleep(self.poll_interval) if not hasattr(settings, 'server_url'): continue try: log.debug("Calling home...") data = { 'playlist': settings.content.playlist_name, 'mac_address': self.mac_address, 'ip_address': utils.get_ip_address(), 'cpu_freq': utils.get_cpu_freq(), 'cpu_temp': utils.get_cpu_temp(), 'cpu_usage': utils.get_cpu_usage(), 'browser_ram': utils.get_pid_rss(self.browser.uzbl.pid), 'uptime': utils.get_uptime() } if self.send_logs: data['logs'] = '\n'.join(utils.get_log_entries()) self.send_logs = False reply = self.call_home(data) log.debug("Got reply %s" % reply) self.do_clock(reply) try: method = getattr(self, 'do_' + reply['action']) except AttributeError: log.debug("Cannot handle reply %s", reply) if app.running: # state may have changed in the meantime method(reply['data']) except Exception as e: log.debug("Got %s while calling home" % e) pass log.info("Exiting beacon thread.")
def run(self): """Thread main loop""" while(app.running): time.sleep(self.poll_interval) if not hasattr(self.config,'server_url'): continue try: log.debug("Calling home...") data = { 'playlist' : self.playlist, 'mac_address' : self.mac_address, 'ip_address' : self.ip_address, 'cpu_freq' : utils.get_cpu_freq(), 'cpu_temp' : utils.get_cpu_temp(), 'cpu_usage' : utils.get_cpu_usage(), 'browser_ram' : utils.get_pid_rss(self.browser.uzbl.pid), 'uptime' : utils.get_uptime() } if self.send_logs: data['logs'] = '\n'.join(utils.get_log_entries()) self.send_logs = False reply = self.call_home(data) log.debug("Got reply %s" % reply) self.do_clock(reply) try: method = getattr(self, 'do_' + reply['action']) except AttributeError: log.debug("Cannot handle reply %s", reply) if app.running: # state may have changed in the meantime method(reply['data']) except Exception as e: log.debug("Got %s while calling home" % e) pass log.info("Exiting beacon thread.")
def do(self, buffer): """Perform a browser command by talking to its FIFO""" returncode = self.uzbl.poll() if returncode == None: # still running # Even though we're using rlimit, the kill/respawn cycle tends to # flash the screen, so we'll still try to do controlled restarts if self.config.uzbl.ram.soft_limit < utils.get_pid_rss(self.uzbl.pid): log.debug("Restarting browser due to memory leak") self.restart() h = open(self.fifo,'a') h.write(buffer + '\n') h.close() else: log.error("Browser exited with return code %s, relaunching" % returncode) self.launch(self.home) self.do(buffer)
def do(self, buffer): """Perform a browser command by talking to its FIFO""" returncode = self.uzbl.poll() if returncode == None: # still running # Even though we're using rlimit, the kill/respawn cycle tends to # flash the screen, so we'll still try to do controlled restarts if settings.uzbl.ram.soft_limit < utils.get_pid_rss(self.uzbl.pid): log.debug("Restarting browser due to memory leak") self.restart() log.debug(buffer) h = open(self.fifo, 'a') # Remove the status bar (failsafe in case some error condition triggers it) h.write("set show_status = 0\n") h.write(buffer + '\n') h.close() else: log.error("Browser exited with return code %s, relaunching" % returncode) self.launch(self.home) self.do(buffer)