2019-08-06 11:04:33 +00:00
|
|
|
"""set_thread_name for threads that don't use StoppableThread"""
|
2018-04-07 09:44:43 +00:00
|
|
|
|
2015-11-22 15:18:59 +00:00
|
|
|
import threading
|
2017-07-10 05:08:10 +00:00
|
|
|
|
2017-07-06 17:35:40 +00:00
|
|
|
try:
|
|
|
|
import prctl
|
2018-04-10 08:49:34 +00:00
|
|
|
except ImportError:
|
|
|
|
def set_thread_name(name):
|
|
|
|
"""Set the thread name for external use (visible from the OS)."""
|
|
|
|
threading.current_thread().name = name
|
|
|
|
else:
|
2018-04-07 09:44:43 +00:00
|
|
|
def set_thread_name(name):
|
2018-04-07 13:12:21 +00:00
|
|
|
"""Set a name for the thread for python internal use."""
|
2018-04-07 09:44:43 +00:00
|
|
|
prctl.set_name(name)
|
2017-07-06 17:35:40 +00:00
|
|
|
|
|
|
|
def _thread_name_hack(self):
|
|
|
|
set_thread_name(self.name)
|
|
|
|
threading.Thread.__bootstrap_original__(self)
|
|
|
|
|
|
|
|
threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
|
|
|
|
threading.Thread._Thread__bootstrap = _thread_name_hack
|