Best Python code snippet using autotest_python
watchdog.py
Source: watchdog.py
...42 if triggers["above"] is not None:43 if isinstance(new, (float, int)):44 if new > triggers["above"]:45 self.log("{} is above {} for {}".format(new, triggers["above"], entity))46 self.update_watchdog(watchdog, entity, "add")47 continue48 if triggers["below"] is not None:49 if isinstance(new, (float, int)):50 if new < triggers["below"]:51 self.log("{} is below {} for {}".format(new, triggers["below"], entity))52 self.update_watchdog(watchdog, entity, "add")53 continue54 if new is None and triggers["state"].lower() == "unknown":55 self.update_watchdog(watchdog, entity, "add")56 continue57 elif isinstance(new, str) and triggers["state"].lower() == new.lower():58 self.update_watchdog(watchdog, entity, "add")59 continue60 self.update_watchdog(watchdog, entity, "remove")61 def update_watchdog(self, watchdog, entity, add_or_remove):62 """Update watchdog info."""63 attributes = {64 "icon": self.watchdog_config[watchdog]["icon"],65 "friendly_name": self.watchdog_config[watchdog]["friendly_name"],66 67 }68 watchdog_state = self.get_state("watchdog.{}".format(watchdog), attribute="all")69 if watchdog_state is None:70 self.set_state("watchdog.{}".format(watchdog),71 state=self.state_normal,72 attributes={"entities": attributes})73 watchdog_state = self.get_state("watchdog.{}".format(watchdog), attribute="all")74 watchdog_attributes = watchdog_state.get("attributes", {})75 watchdog_entities = watchdog_attributes.get("entities", [])...
watchdog2.py
Source: watchdog2.py
...12 charset='utf8'13)14cursor = sieve_db.cursor(pymysql.cursors.DictCursor)15HOST = "165.132.105.40"16def update_watchdog(timestamp, lis_port, cpu_usage, mem_usage) :17 sql = 'UPDATE job_tasks SET cpu_usage=' + str(cpu_usage) + ' WHERE ec_id=' + str(ec_id) + ' AND listening_port=' + str(lis_port)18 cursor.execute(sql)19 sieve_db.commit()20sql = 'SELECT id FROM engine_computer where ip_address="' + HOST + '"'21cursor.execute(sql)22ec_id = (cursor.fetchall())[0]['id']23while True :24 pids = []25 pair = {}26 for proc in psutil.process_iter() :27 try :28 if proc.name() == "python3" or proc.name() == "python3.6":29 port = proc.cmdline()[3]30 pids.append(proc.pid)31 pair[proc.pid] = port32 except :33 pass34 print("pids : ", pids)35 print("pair : ", pair)36 for pid in pids :37 cmd = ['ps', '-p', str(pid), '-o', '%cpu'] 38 fd_popen = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout 39 data = fd_popen.read().strip() 40 fd_popen.close()41 data = data.decode('utf-8')42 data = data.split('\n')43 lis_port = pair[pid]44 cpu_usage = data[1]45 print(pid, lis_port, cpu_usage)46 update_watchdog(1, lis_port, cpu_usage, 10)...
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!!