From ba0d687b639e51299b7172adc7e532155c37938b Mon Sep 17 00:00:00 2001 From: clerie Date: Fri, 2 Sep 2022 21:07:39 +0200 Subject: [PATCH] Refactor thread handling --- fieldpoc/fieldpoc.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/fieldpoc/fieldpoc.py b/fieldpoc/fieldpoc.py index 3dd63e2..72f5f39 100644 --- a/fieldpoc/fieldpoc.py +++ b/fieldpoc/fieldpoc.py @@ -39,6 +39,18 @@ class FieldPOC: self._routing = routing.Routing(self) self._ywsd = ywsd.Ywsd(self) + logger.info("initialising threads") + self.threads = { + "controller": threading.Thread(target=self._controller.run), + "dect": threading.Thread(target=self._dect.run), + "routing": threading.Thread(target=self._routing.run), + "ywsd": threading.Thread(target=self._ywsd.run, daemon=True), + } + + # Set thread names + for name, thread in self.threads.items(): + thread.name = name + def queue_all(self, msg): """ Send message to every queue @@ -60,21 +72,16 @@ class FieldPOC: logger.info("initialization complete") def run(self): - logger.info("starting components") + """ + Start FieldPOC + """ - self._controller_thread = threading.Thread(target=self._controller.run) - self._controller_thread.start() + logger.info("starting threads") - self._dect_thread = threading.Thread(target=self._dect.run) - self._dect_thread.start() + for name, thread in self.threads.items(): + thread.start() - self._routing_thread = threading.Thread(target=self._routing.run) - self._routing_thread.start() - - self._ywsd_thread = threading.Thread(target=self._ywsd.run, daemon=True) - self._ywsd_thread.start() - - logger.info("started components") + logger.info("started threads") def reload_extensions(self): self._load_extensions()