mirror of
https://github.com/searxng/searxng.git
synced 2025-07-24 21:59:22 +02:00
[mod] multithreading only in searx.search.* packages
it prepares the new architecture change, everything about multithreading in moved in the searx.search.* packages previously the call to the "init" function of the engines was done in searx.engines: * the network was not set (request not sent using the defined proxy) * it requires to monkey patch the code to avoid HTTP requests during the tests
This commit is contained in:
parent
d36adfa59f
commit
8c1a65d32f
10 changed files with 85 additions and 65 deletions
|
@ -13,7 +13,8 @@ from searx import logger
|
|||
from searx.engines import settings
|
||||
from searx.network import get_time_for_thread, get_network
|
||||
from searx.metrics import histogram_observe, counter_inc, count_exception, count_error
|
||||
from searx.exceptions import SearxEngineAccessDeniedException
|
||||
from searx.exceptions import SearxEngineAccessDeniedException, SearxEngineResponseException
|
||||
from searx.utils import get_engine_from_settings
|
||||
|
||||
logger = logger.getChild('searx.search.processor')
|
||||
SUSPENDED_STATUS = {}
|
||||
|
@ -66,6 +67,20 @@ class EngineProcessor(ABC):
|
|||
key = id(key) if key else self.engine_name
|
||||
self.suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
|
||||
|
||||
def initialize(self):
|
||||
try:
|
||||
self.engine.init(get_engine_from_settings(self.engine_name))
|
||||
except SearxEngineResponseException as exc:
|
||||
logger.warn('%s engine: Fail to initialize // %s', self.engine_name, exc)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
logger.exception('%s engine: Fail to initialize', self.engine_name)
|
||||
else:
|
||||
logger.debug('%s engine: Initialized', self.engine_name)
|
||||
|
||||
@property
|
||||
def has_initialize_function(self):
|
||||
return hasattr(self.engine, 'init')
|
||||
|
||||
def handle_exception(self, result_container, exception_or_message, suspend=False):
|
||||
# update result_container
|
||||
if isinstance(exception_or_message, BaseException):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue