unixthreadname.py 549 B

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