mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
[mod] move hook to set Unix thread name into searx.unixthreadname
requires setproctitle (but optional)
This commit is contained in:
20
searx/unixthreadname.py
Normal file
20
searx/unixthreadname.py
Normal 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
|
||||
Reference in New Issue
Block a user