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,6 +60,7 @@ class CpuUsageThread(threading.Thread):
def add_client(self, c): def add_client(self, c):
self.clients.append(c) self.clients.append(c)
with self.startLock:
if not self.is_alive(): if not self.is_alive():
self.start() self.start()