瀏覽代碼

[mod] separate engine load and initialization

Adam Tauber 7 年之前
父節點
當前提交
0f6612bb40
共有 1 個文件被更改,包括 17 次插入10 次删除
  1. 17
    10
      searx/engines/__init__.py

+ 17
- 10
searx/engines/__init__.py 查看文件

@@ -85,15 +85,6 @@ def load_engine(engine_data):
85 85
     for engine_attr in dir(engine):
86 86
         if engine_attr.startswith('_'):
87 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 88
         if engine_attr == 'inactive' and getattr(engine, engine_attr) is True:
98 89
             return None
99 90
         if getattr(engine, engine_attr) is None:
@@ -226,8 +217,24 @@ def get_engines_stats():
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 223
     for engine_data in engine_list:
231 224
         engine = load_engine(engine_data)
232 225
         if engine is not None:
233 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()