mirror of
https://github.com/searxng/searxng.git
synced 2024-12-21 00:36:29 +00:00
[enh] add init function to engines which loads parallel
This commit is contained in:
parent
f82646f386
commit
78365ffb8a
3 changed files with 17 additions and 4 deletions
|
@ -16,8 +16,9 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||||
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
|
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from os.path import realpath, dirname
|
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
|
from os.path import realpath, dirname
|
||||||
from flask_babel import gettext
|
from flask_babel import gettext
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from json import loads
|
from json import loads
|
||||||
|
@ -84,6 +85,14 @@ def load_engine(engine_data):
|
||||||
for engine_attr in dir(engine):
|
for engine_attr in dir(engine):
|
||||||
if engine_attr.startswith('_'):
|
if engine_attr.startswith('_'):
|
||||||
continue
|
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:
|
if getattr(engine, engine_attr) is None:
|
||||||
logger.error('Missing engine config attribute: "{0}.{1}"'
|
logger.error('Missing engine config attribute: "{0}.{1}"'
|
||||||
.format(engine.name, engine_attr))
|
.format(engine.name, engine_attr))
|
||||||
|
|
|
@ -41,6 +41,7 @@ embedded_url = '<iframe width="100%" height="166" ' +\
|
||||||
'data-src="https://w.soundcloud.com/player/?url={uri}"></iframe>'
|
'data-src="https://w.soundcloud.com/player/?url={uri}"></iframe>'
|
||||||
|
|
||||||
cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)
|
cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)
|
||||||
|
guest_client_id = ''
|
||||||
|
|
||||||
|
|
||||||
def get_client_id():
|
def get_client_id():
|
||||||
|
@ -63,6 +64,8 @@ def get_client_id():
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
global guest_client_id
|
||||||
# api-key
|
# api-key
|
||||||
guest_client_id = get_client_id()
|
guest_client_id = get_client_id()
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ def obtain_token():
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
obtain_token()
|
obtain_token()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue