summaryrefslogtreecommitdiff
path: root/searx/unixthreadname.py
blob: 3c2a68917149dcee38cf92ef3ec6c2fb0ae9c500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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
        old_thread_init(self, *args, **kwargs)
        setproctitle.setthreadtitle(self._name)

    threading.Thread.__init__ = new_thread_init