try to avoid "can only be started once" error

This commit is contained in:
Jakob Ketterl 2021-12-27 16:37:10 +01:00
parent 46c78f6463
commit 221e0f232b

View File

@ -22,6 +22,7 @@ class CpuUsageThread(threading.Thread):
self.last_worktime = 0 self.last_worktime = 0
self.last_idletime = 0 self.last_idletime = 0
self.endEvent = threading.Event() self.endEvent = threading.Event()
self.startLock = threading.Lock()
super().__init__() super().__init__()
def run(self): def run(self):
@ -59,8 +60,9 @@ class CpuUsageThread(threading.Thread):
def add_client(self, c): def add_client(self, c):
self.clients.append(c) self.clients.append(c)
if not self.is_alive(): with self.startLock:
self.start() if not self.is_alive():
self.start()
def remove_client(self, c): def remove_client(self, c):
try: try: