mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 12:10:11 +01:00
[fix] ResultContainer: use self._lock and self._closed for all properties
Close #3474
This commit is contained in:
parent
68365c8c1d
commit
75e4b65127
@ -430,6 +430,11 @@ class ResultContainer:
|
|||||||
"""Returns the average of results number, returns zero if the average
|
"""Returns the average of results number, returns zero if the average
|
||||||
result number is smaller than the actual result count."""
|
result number is smaller than the actual result count."""
|
||||||
|
|
||||||
|
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)
|
resultnum_sum = sum(self._number_of_results)
|
||||||
if not resultnum_sum or not self._number_of_results:
|
if not resultnum_sum or not self._number_of_results:
|
||||||
return 0
|
return 0
|
||||||
@ -440,11 +445,23 @@ class ResultContainer:
|
|||||||
return average
|
return average
|
||||||
|
|
||||||
def add_unresponsive_engine(self, engine_name: str, error_type: str, suspended: bool = False):
|
def add_unresponsive_engine(self, engine_name: str, error_type: str, suspended: bool = False):
|
||||||
|
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:
|
if engines[engine_name].display_error_messages:
|
||||||
self.unresponsive_engines.add(UnresponsiveEngine(engine_name, error_type, suspended))
|
self.unresponsive_engines.add(UnresponsiveEngine(engine_name, error_type, suspended))
|
||||||
|
|
||||||
def add_timing(self, engine_name: str, engine_time: float, page_load_time: float):
|
def add_timing(self, engine_name: str, engine_time: float, page_load_time: float):
|
||||||
|
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))
|
self.timings.append(Timing(engine_name, total=engine_time, load=page_load_time))
|
||||||
|
|
||||||
def get_timings(self):
|
def get_timings(self):
|
||||||
|
with self._lock:
|
||||||
|
if not self._closed:
|
||||||
|
logger.error("call to ResultContainer.get_timings before ResultContainer.close")
|
||||||
|
return []
|
||||||
return self.timings
|
return self.timings
|
||||||
|
Loading…
Reference in New Issue
Block a user