From 72f92a1c2b7cff97e388b89617c5e9918729eb44 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Mon, 23 Sep 2019 03:06:51 +0200 Subject: [PATCH] use events instead of simple sleep for clean shutdown --- owrx/source.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/owrx/source.py b/owrx/source.py index 2c475ec..428955c 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -642,6 +642,7 @@ class CpuUsageThread(threading.Thread): self.doRun = True self.last_worktime = 0 self.last_idletime = 0 + self.endEvent = threading.Event() super().__init__() def run(self): @@ -652,7 +653,7 @@ class CpuUsageThread(threading.Thread): cpu_usage = 0 for c in self.clients: c.write_cpu_usage(cpu_usage) - time.sleep(3) + self.endEvent.wait(timeout=3) logger.debug("cpu usage thread shut down") def get_cpu_usage(self): @@ -692,6 +693,7 @@ class CpuUsageThread(threading.Thread): def shutdown(self): CpuUsageThread.sharedInstance = None self.doRun = False + self.endEvent.set() class TooManyClientsException(Exception):