1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-17 18:00:12 +01:00

[mod] move hook to set Unix thread name into searx.unixthreadname

requires setproctitle (but optional)
This commit is contained in:
Alexandre Flament 2021-06-08 11:34:36 +02:00
parent 0e23113f70
commit 70bbd14b1a
3 changed files with 21 additions and 15 deletions

View File

@ -5,6 +5,7 @@
from os.path import dirname, abspath from os.path import dirname, abspath
import logging import logging
import searx.unixthreadname
import searx.settings_loader import searx.settings_loader
from searx.settings_defaults import settings_set_defaults from searx.settings_defaults import settings_set_defaults

20
searx/unixthreadname.py Normal file
View File

@ -0,0 +1,20 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""
if setproctitle is installed.
set Unix thread name with the Python thread name
"""
try:
import setproctitle
except ImportError:
pass
else:
import threading
old_thread_init = threading.Thread.__init__
def new_thread_init(self, *args, **kwargs):
# pylint: disable=protected-access, disable=c-extension-no-member, disable=missing-function-docstring
old_thread_init(self, *args, **kwargs)
setproctitle.setthreadtitle(self._name)
threading.Thread.__init__ = new_thread_init

View File

@ -111,21 +111,6 @@ from searx.network import stream as http_stream
from searx.search.checker import get_result as checker_get_result from searx.search.checker import get_result as checker_get_result
from searx.settings_loader import get_default_settings_path from searx.settings_loader import get_default_settings_path
# set Unix thread name
try:
import setproctitle
except ImportError:
pass
else:
import threading
old_thread_init = threading.Thread.__init__
def new_thread_init(self, *args, **kwargs):
# pylint: disable=protected-access, disable=c-extension-no-member
old_thread_init(self, *args, **kwargs)
setproctitle.setthreadtitle(self._name)
threading.Thread.__init__ = new_thread_init
logger = logger.getChild('webapp') logger = logger.getChild('webapp')
# check secret_key # check secret_key