unixthreadname.py 534 B

12345678910111213141516171819202122
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. if setproctitle is installed.
  4. set Unix thread name with the Python thread name
  5. """
  6. try:
  7. import setproctitle
  8. except ImportError:
  9. pass
  10. else:
  11. import threading
  12. old_thread_init = threading.Thread.__init__
  13. def new_thread_init(self, *args, **kwargs):
  14. # pylint: disable=protected-access, disable=c-extension-no-member
  15. old_thread_init(self, *args, **kwargs)
  16. setproctitle.setthreadtitle(self._name)
  17. threading.Thread.__init__ = new_thread_init