Best Python code snippet using locust
runners.py
Source:runners.py
...267 stop_group.kill(block=True)268 logger.debug(269 "%g users have been stopped, %g still running", sum(user_classes_stop_count.values()), self.user_count270 )271 def monitor_cpu_and_memory(self) -> NoReturn:272 process = psutil.Process()273 while True:274 self.current_cpu_usage = process.cpu_percent()275 self.current_memory_usage = process.memory_info().rss276 if self.current_cpu_usage > CPU_WARNING_THRESHOLD:277 self.environment.events.cpu_warning.fire(environment=self.environment, cpu_usage=self.current_cpu_usage)278 if not self.cpu_warning_emitted:279 logging.warning(280 f"CPU usage above {CPU_WARNING_THRESHOLD}%! This may constrain your throughput and may even give inconsistent response time measurements! See https://docs.locust.io/en/stable/running-locust-distributed.html for how to distribute the load over multiple CPU cores or machines"281 )282 self.cpu_warning_emitted = True283 gevent.sleep(CPU_MONITOR_INTERVAL)284 @abstractmethod285 def start(self, user_count: int, spawn_rate: float, wait: bool = False) -> None:...
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!!