Browse Source

[mod] separate engine load and initialization

Adam Tauber 7 years ago
parent
commit
0f6612bb40
1 changed files with 17 additions and 10 deletions
  1. 17
    10
      searx/engines/__init__.py

+ 17
- 10
searx/engines/__init__.py View File

85
     for engine_attr in dir(engine):
85
     for engine_attr in dir(engine):
86
         if engine_attr.startswith('_'):
86
         if engine_attr.startswith('_'):
87
             continue
87
             continue
88
-        if engine_attr == 'init':
89
-            init_fn = getattr(engine, engine_attr)
90
-
91
-            def engine_init():
92
-                init_fn()
93
-                logger.debug('%s engine initialized', engine_data['name'])
94
-            logger.debug('Starting background initialization of %s engine', engine_data['name'])
95
-            threading.Thread(target=engine_init).start()
96
-            continue
97
         if engine_attr == 'inactive' and getattr(engine, engine_attr) is True:
88
         if engine_attr == 'inactive' and getattr(engine, engine_attr) is True:
98
             return None
89
             return None
99
         if getattr(engine, engine_attr) is None:
90
         if getattr(engine, engine_attr) is None:
226
     ]
217
     ]
227
 
218
 
228
 
219
 
229
-def initialize_engines(engine_list):
220
+def load_engines(engine_list):
221
+    global engines
222
+    engines.clear()
230
     for engine_data in engine_list:
223
     for engine_data in engine_list:
231
         engine = load_engine(engine_data)
224
         engine = load_engine(engine_data)
232
         if engine is not None:
225
         if engine is not None:
233
             engines[engine.name] = engine
226
             engines[engine.name] = engine
227
+    return engines
228
+
229
+
230
+def initialize_engines(engine_list):
231
+    load_engines(engine_list)
232
+    for engine in engines.items():
233
+        if hasattr(engine, 'init'):
234
+            init_fn = getattr(engine, engine_attr)
235
+
236
+            def engine_init():
237
+                init_fn()
238
+                logger.debug('%s engine initialized', engine_data['name'])
239
+            logger.debug('Starting background initialization of %s engine', engine_data['name'])
240
+            threading.Thread(target=engine_init).start()