Refactor thread handling

This commit is contained in:
clerie 2022-09-02 21:07:39 +02:00
parent 035576dff0
commit ba0d687b63

View File

@ -39,6 +39,18 @@ class FieldPOC:
self._routing = routing.Routing(self) self._routing = routing.Routing(self)
self._ywsd = ywsd.Ywsd(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): def queue_all(self, msg):
""" """
Send message to every queue Send message to every queue
@ -60,21 +72,16 @@ class FieldPOC:
logger.info("initialization complete") logger.info("initialization complete")
def run(self): def run(self):
logger.info("starting components") """
Start FieldPOC
"""
self._controller_thread = threading.Thread(target=self._controller.run) logger.info("starting threads")
self._controller_thread.start()
self._dect_thread = threading.Thread(target=self._dect.run) for name, thread in self.threads.items():
self._dect_thread.start() thread.start()
self._routing_thread = threading.Thread(target=self._routing.run) logger.info("started threads")
self._routing_thread.start()
self._ywsd_thread = threading.Thread(target=self._ywsd.run, daemon=True)
self._ywsd_thread.start()
logger.info("started components")
def reload_extensions(self): def reload_extensions(self):
self._load_extensions() self._load_extensions()