Fix not-stopping on loop

This commit is contained in:
Ruben van de Ven 2023-10-22 14:03:18 +02:00
parent 185962ace5
commit b911caa5af

View file

@ -156,9 +156,12 @@ class WsRouter:
async def prediction_forwarder(self): async def prediction_forwarder(self):
logger.info("Starting prediction forwarder") logger.info("Starting prediction forwarder")
while self.is_running.is_set(): while self.is_running.is_set():
msg = await self.prediction_socket.recv_string() # timeout so that if no events occur, loop can still stop on is_running
logger.debug(f"Forward prediction message of {len(msg)} chars") has_event = await self.prediction_socket.poll(timeout=1)
WebSocketPredictionHandler.write_to_clients(msg) if has_event:
msg = await self.prediction_socket.recv_string()
logger.debug(f"Forward prediction message of {len(msg)} chars")
WebSocketPredictionHandler.write_to_clients(msg)
# die together: # die together:
self.evt_loop.stop() self.evt_loop.stop()