diff options
author | Adam Tauber <asciimoo@gmail.com> | 2017-07-21 14:27:25 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-07-21 14:27:25 +0200 |
commit | 0f6612bb40f28c5d517c96bc07aa19123312a1ba (patch) | |
tree | 681bd4d44a35013febf97adf9e27eb288637c56f /searx | |
parent | f2b13a7de071cd68c9aeef7ff3e87ede88e677e8 (diff) | |
download | searxng-0f6612bb40f28c5d517c96bc07aa19123312a1ba.tar.gz searxng-0f6612bb40f28c5d517c96bc07aa19123312a1ba.zip |
[mod] separate engine load and initialization
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/__init__.py | 27 |
1 files 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() |