Best Python code snippet using autotest_python
monitor_db_babysitter
Source: monitor_db_babysitter
...23 print " -r Run recovery mode. (Note: recovery is implicit after"24 print " any crash!)"25 print26 sys.exit(1)27def run_banner_output(cmd):28 """Returns ------ CMD ------\nCMD_OUTPUT in a string"""29 banner_output = '%s\n%%s\n\n' % cmd.center(60, '-')30 command_output = ''31 try:32 cmd_out = utils.run(cmd, ignore_status=True, timeout=30)33 command_output = cmd_out.stdout + cmd_out.stderr34 except error.CmdError:35 command_output = 'Timed out'36 return banner_output % command_output37def kill_all_monitors():38 logging.info("Killing all monitor_dbs")39 # try shutdown first40 status = os.system("killall -2 monitor_db.py")41 if status == 0: # were any killed?42 # give them some time to shutdown43 time.sleep(30)44 # kill any that are left45 os.system("killall monitor_db.py")46def handle_sigterm(signum, frame):47 logging.info('Caught SIGTERM')48 kill_all_monitors()49 sys.exit(1)50signal.signal(signal.SIGTERM, handle_sigterm)51class MonitorProc:52 def __init__(self, do_recovery=False):53 args = [monitor_db]54 if do_recovery:55 args.append("--recover-hosts")56 args.append(results_dir)57 kill_all_monitors()58 environ = os.environ59 scheduler_config = scheduler_logging_config.SchedulerLoggingConfig60 log_name = scheduler_config.get_log_name()61 os.environ['AUTOTEST_SCHEDULER_LOG_NAME'] = log_name62 scheduler_log_dir = scheduler_config.get_server_log_dir()63 self.log_path = os.path.join(scheduler_log_dir, log_name)64 self.log_size = 065 self.last_log_change = time.time()66 logging.info("STARTING monitor_db with log file %s" % self.log_path)67 devnull = open(os.devnull, 'w')68 self.proc = subprocess.Popen(args, stdout=devnull)69 def is_running(self):70 if self.proc.poll() is not None:71 logging.info("monitor_db DIED")72 return False73 old_size = self.log_size74 new_size = os.path.getsize(self.log_path)75 if old_size != new_size:76 logging.info("Log was touched")77 self.log_size = new_size78 self.last_log_change = time.time()79 elif self.last_log_change + STALL_TIMEOUT < time.time():80 logging.info("monitor_db STALLED")81 self.collect_stalled_info()82 return False83 return True84 def collect_stalled_info(self):85 INFO_TO_COLLECT = ['uptime',86 'ps auxwww',87 'iostat -k -x 2 4',88 ]89 db_cmd = '/usr/bin/mysqladmin --verbose processlist -u%s -p%s'90 config = global_config.global_config91 try:92 user = config.get_config_value("BACKUP", "user")93 password = config.get_config_value("BACKUP", "password")94 db_cmd %= (user, password)95 INFO_TO_COLLECT.append(db_cmd)96 except global_config.ConfigError:97 pass98 stall_log_path = self.log_path + '.stall_info'99 log = open(stall_log_path, "w")100 for cmd in INFO_TO_COLLECT:101 log.write(run_banner_output(cmd))102 log.close()103logging.info("initializing")104if os.getuid() == 0:105 logging.critical("running as root, aborting!")106 sys.exit(1)107utils.write_pid("monitor_db_babysitter")108while True:109 proc = MonitorProc(do_recovery=recover)110 time.sleep(PAUSE_LENGTH)111 while proc.is_running():112 logging.info("Tick")113 time.sleep(PAUSE_LENGTH)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!