From 6c39917c4d3e3d3d6ced3fc14d1c78842fec3a19 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Thu, 1 Oct 2020 14:18:00 +0200 Subject: [mod] webapp.py: update engines initialization condition Always call initialize engines except on the first run of werkzeug with the reload feature. the reload feature is activated when: * searx_debug is True (SEARX_DEBUG environment variable or settings.yml) * FLASK_APP=searx/webapp.py FLASK_ENV=development flask run (see https://flask.palletsprojects.com/en/1.1.x/cli/ ) Fix SEARX_DEBUG=0 make docs docs/admin/engines.rst : engines are initialized See https://github.com/searx/searx/issues/2204#issuecomment-701373438 --- searx/webutils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'searx/webutils.py') diff --git a/searx/webutils.py b/searx/webutils.py index 2900c0edd..bf50dbc25 100644 --- a/searx/webutils.py +++ b/searx/webutils.py @@ -4,6 +4,7 @@ import csv import hashlib import hmac import re +import inspect from io import StringIO from codecs import getincrementalencoder @@ -125,3 +126,18 @@ def highlight_content(content, query): content, flags=re.I | re.U) return content + + +def is_flask_run_cmdline(): + """Check if the application was started using "flask run" command line + + Inspect the callstack. + See https://github.com/pallets/flask/blob/master/src/flask/__main__.py + + Returns: + bool: True if the application was started using "flask run". + """ + frames = inspect.stack() + if len(frames) < 2: + return False + return frames[-2].filename.endswith('flask/cli.py') -- cgit v1.2.3