use events instead of simple sleep for clean shutdown
This commit is contained in:
parent
8b9121a5c1
commit
72f92a1c2b
@ -642,6 +642,7 @@ class CpuUsageThread(threading.Thread):
|
|||||||
self.doRun = True
|
self.doRun = True
|
||||||
self.last_worktime = 0
|
self.last_worktime = 0
|
||||||
self.last_idletime = 0
|
self.last_idletime = 0
|
||||||
|
self.endEvent = threading.Event()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -652,7 +653,7 @@ class CpuUsageThread(threading.Thread):
|
|||||||
cpu_usage = 0
|
cpu_usage = 0
|
||||||
for c in self.clients:
|
for c in self.clients:
|
||||||
c.write_cpu_usage(cpu_usage)
|
c.write_cpu_usage(cpu_usage)
|
||||||
time.sleep(3)
|
self.endEvent.wait(timeout=3)
|
||||||
logger.debug("cpu usage thread shut down")
|
logger.debug("cpu usage thread shut down")
|
||||||
|
|
||||||
def get_cpu_usage(self):
|
def get_cpu_usage(self):
|
||||||
@ -692,6 +693,7 @@ class CpuUsageThread(threading.Thread):
|
|||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
CpuUsageThread.sharedInstance = None
|
CpuUsageThread.sharedInstance = None
|
||||||
self.doRun = False
|
self.doRun = False
|
||||||
|
self.endEvent.set()
|
||||||
|
|
||||||
|
|
||||||
class TooManyClientsException(Exception):
|
class TooManyClientsException(Exception):
|
||||||
|
Loading…
Reference in New Issue
Block a user