diff --git a/trap/socket_forwarder.py b/trap/socket_forwarder.py index 654128d..a5ab499 100644 --- a/trap/socket_forwarder.py +++ b/trap/socket_forwarder.py @@ -156,9 +156,12 @@ class WsRouter: async def prediction_forwarder(self): logger.info("Starting prediction forwarder") while self.is_running.is_set(): - msg = await self.prediction_socket.recv_string() - logger.debug(f"Forward prediction message of {len(msg)} chars") - WebSocketPredictionHandler.write_to_clients(msg) + # timeout so that if no events occur, loop can still stop on is_running + has_event = await self.prediction_socket.poll(timeout=1) + 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: self.evt_loop.stop()