Best Python code snippet using locust
stats.py
Source:stats.py  
...806            now = time.time()807            self.requests_csv_filehandle.seek(requests_csv_data_start)808            self._requests_data_rows(self.requests_csv_writer)809            self.requests_csv_filehandle.truncate()810            self._stats_history_data_rows(self.stats_history_csv_writer, now)811            self.failures_csv_filehandle.seek(self.failures_csv_data_start)812            self._failures_data_rows(self.failures_csv_writer)813            self.failures_csv_filehandle.truncate()814            self.exceptions_csv_filehandle.seek((self.exceptions_csv_data_start))815            self._exceptions_data_rows(self.exceptions_csv_writer)816            self.exceptions_csv_filehandle.truncate()817            if now - last_flush_time > CSV_STATS_FLUSH_INTERVAL_SEC:818                self.requests_flush()819                self.stats_history_flush()820                self.failures_flush()821                self.exceptions_flush()822                last_flush_time = now823            gevent.sleep(CSV_STATS_INTERVAL_SEC)824    def _stats_history_data_rows(self, csv_writer, now):825        """826        Write CSV rows with the *current* stats. By default only includes the827        Aggregated stats entry, but if self.full_history is set to True, a row for each entry will828        will be included.829        Note that this method differs from the other methods as it appends time-stamped data to the file, whereas the other methods overwrites the data.830        """831        stats = self.environment.stats832        timestamp = int(now)833        stats_entries = []834        if self.full_history:835            stats_entries = sort_stats(stats.entries)836        for stats_entry in chain(stats_entries, [stats.total]):837            csv_writer.writerow(838                chain(...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!!
