From 0f6612bb40f28c5d517c96bc07aa19123312a1ba Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 21 Jul 2017 14:27:25 +0200 Subject: [PATCH] [mod] separate engine load and initialization --- searx/engines/__init__.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 48c9b7e4a..7a9cc56a2 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -85,15 +85,6 @@ def load_engine(engine_data): for engine_attr in dir(engine): if engine_attr.startswith('_'): continue - if engine_attr == 'init': - init_fn = getattr(engine, engine_attr) - - def engine_init(): - init_fn() - logger.debug('%s engine initialized', engine_data['name']) - logger.debug('Starting background initialization of %s engine', engine_data['name']) - threading.Thread(target=engine_init).start() - continue if engine_attr == 'inactive' and getattr(engine, engine_attr) is True: return None if getattr(engine, engine_attr) is None: @@ -226,8 +217,24 @@ def get_engines_stats(): ] -def initialize_engines(engine_list): +def load_engines(engine_list): + global engines + engines.clear() for engine_data in engine_list: engine = load_engine(engine_data) if engine is not None: engines[engine.name] = engine + return engines + + +def initialize_engines(engine_list): + load_engines(engine_list) + for engine in engines.items(): + if hasattr(engine, 'init'): + init_fn = getattr(engine, engine_attr) + + def engine_init(): + init_fn() + logger.debug('%s engine initialized', engine_data['name']) + logger.debug('Starting background initialization of %s engine', engine_data['name']) + threading.Thread(target=engine_init).start()