diff options
author | Alexandre Flament <alex@al-f.net> | 2024-05-18 21:16:09 +0000 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-05-24 15:38:03 +0200 |
commit | 75e4b65127668a1d3bfe559ecca38687b6433a7c (patch) | |
tree | dfb264c54b4f19753ed47848ed493a335e99bfd7 /searx/results.py | |
parent | 68365c8c1d819338337e7729424a435ebf269061 (diff) | |
download | searxng-75e4b65127668a1d3bfe559ecca38687b6433a7c.tar.gz searxng-75e4b65127668a1d3bfe559ecca38687b6433a7c.zip |
[fix] ResultContainer: use self._lock and self._closed for all properties
Close #3474
Diffstat (limited to 'searx/results.py')
-rw-r--r-- | searx/results.py | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/searx/results.py b/searx/results.py index 023d2edf6..8b248f8e0 100644 --- a/searx/results.py +++ b/searx/results.py @@ -430,21 +430,38 @@ class ResultContainer: """Returns the average of results number, returns zero if the average result number is smaller than the actual result count.""" - resultnum_sum = sum(self._number_of_results) - if not resultnum_sum or not self._number_of_results: - return 0 + with self._lock: + if not self._closed: + logger.error("call to ResultContainer.number_of_results before ResultContainer.close") + return 0 + + resultnum_sum = sum(self._number_of_results) + if not resultnum_sum or not self._number_of_results: + return 0 - average = int(resultnum_sum / len(self._number_of_results)) - if average < self.results_length(): - average = 0 - return average + average = int(resultnum_sum / len(self._number_of_results)) + if average < self.results_length(): + average = 0 + return average def add_unresponsive_engine(self, engine_name: str, error_type: str, suspended: bool = False): - if engines[engine_name].display_error_messages: - self.unresponsive_engines.add(UnresponsiveEngine(engine_name, error_type, suspended)) + with self._lock: + if self._closed: + logger.error("call to ResultContainer.add_unresponsive_engine after ResultContainer.close") + return + if engines[engine_name].display_error_messages: + self.unresponsive_engines.add(UnresponsiveEngine(engine_name, error_type, suspended)) def add_timing(self, engine_name: str, engine_time: float, page_load_time: float): - self.timings.append(Timing(engine_name, total=engine_time, load=page_load_time)) + with self._lock: + if self._closed: + logger.error("call to ResultContainer.add_timing after ResultContainer.close") + return + self.timings.append(Timing(engine_name, total=engine_time, load=page_load_time)) def get_timings(self): - return self.timings + with self._lock: + if not self._closed: + logger.error("call to ResultContainer.get_timings before ResultContainer.close") + return [] + return self.timings |