Thread names propagate to system

- the thread names should now show up in the monitoring tools of
operating systems (tested on linux)
This commit is contained in:
Peter Šurda 2017-07-06 19:35:40 +02:00
parent 00a4558971
commit 4536e44b8c
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 18 additions and 3 deletions

View File

@ -63,7 +63,7 @@ from network.downloadthread import DownloadThread
# Helper Functions
import helper_bootstrap
import helper_generic
from helper_threading import *
import helper_threading
def connectToStream(streamNumber):
@ -153,7 +153,7 @@ def _fixSocket():
socket.IPV6_V6ONLY = 27
# This thread, of which there is only one, runs the API.
class singleAPI(threading.Thread, StoppableThread):
class singleAPI(threading.Thread, helper_threading.StoppableThread):
def __init__(self):
threading.Thread.__init__(self, name="singleAPI")
self.initStop()
@ -204,6 +204,8 @@ class Main:
self.setSignalHandler()
helper_threading.set_thread_name("MainThread")
helper_bootstrap.knownNodes()
# Start the address generation thread
addressGeneratorThread = addressGenerator()

View File

@ -1,4 +1,17 @@
import threading
try:
import prctl
def set_thread_name(name): prctl.set_name(name)
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
except ImportError:
log('WARN: prctl module is not installed. You will not be able to see thread names')
def set_thread_name(name): pass
class StoppableThread(object):
def initStop(self):
@ -7,4 +20,4 @@ class StoppableThread(object):
def stopThread(self):
self._stopped = True
self.stop.set()
self.stop.set()