diff options
| author | Adam Tauber <asciimoo@gmail.com> | 2017-06-06 22:20:20 +0200 |
|---|---|---|
| committer | Adam Tauber <asciimoo@gmail.com> | 2017-06-06 22:20:20 +0200 |
| commit | 78365ffb8a083ca3e3ea905db12bdac9f273f460 (patch) | |
| tree | 874334a20ca366f06c026ea326ec239737b7d57d /searx/engines/__init__.py | |
| parent | f82646f38605a999f22bc4662f591cd56d022170 (diff) | |
[enh] add init function to engines which loads parallel
Diffstat (limited to 'searx/engines/__init__.py')
| -rw-r--r-- | searx/engines/__init__.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 023ec409a..1810f1c50 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -16,8 +16,9 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >. (C) 2013- by Adam Tauber, <asciimoo@gmail.com> ''' -from os.path import realpath, dirname import sys +import threading +from os.path import realpath, dirname from flask_babel import gettext from operator import itemgetter from json import loads @@ -84,6 +85,14 @@ 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 getattr(engine, engine_attr) is None: logger.error('Missing engine config attribute: "{0}.{1}"' .format(engine.name, engine_attr)) |