Skip to content

Commit 827c9da

Browse files
committed
forgot to remove _run and _broadcast_to_clients.
1 parent 18f4793 commit 827c9da

2 files changed

Lines changed: 1 addition & 58 deletions

File tree

src/MoBI_View/web/broadcaster.py

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def start(self) -> None:
6767
return
6868

6969
self._running = True
70-
self._thread = threading.Thread(target=self._run, daemon=True)
70+
self._thread = threading.Thread(target=lambda: None, daemon=True)
7171
self._thread.start()
7272
logger.info("Broadcaster started")
7373

@@ -133,59 +133,3 @@ def format_frame(self, streams_data: List[Dict[str, Any]]) -> str:
133133
"streams": streams_data,
134134
}
135135
return json.dumps(frame)
136-
137-
def _run(self) -> None:
138-
"""Main broadcast loop running in background thread.
139-
140-
Continuously polls the presenter for data, formats it, and broadcasts
141-
to all connected clients. Runs until stop() is called.
142-
"""
143-
self._loop = asyncio.new_event_loop()
144-
asyncio.set_event_loop(self._loop)
145-
146-
logger.info("Broadcast loop started")
147-
148-
while self._running:
149-
try:
150-
streams_data = self.presenter.poll_data()
151-
152-
if streams_data:
153-
frame = self.format_frame(streams_data)
154-
self._broadcast_to_clients(frame)
155-
156-
time.sleep(self.broadcast_interval)
157-
158-
except Exception as err:
159-
logger.error("Error in broadcast loop: %s", err)
160-
time.sleep(self.broadcast_interval)
161-
162-
self._loop.close()
163-
logger.info("Broadcast loop ended")
164-
165-
def _broadcast_to_clients(self, message: str) -> None:
166-
"""Sends a message to all connected clients.
167-
168-
Iterates through all clients and sends the message asynchronously.
169-
Disconnected clients are removed from the set.
170-
171-
Args:
172-
message: The JSON message string to broadcast.
173-
"""
174-
with self._clients_lock:
175-
clients_snapshot = set(self.clients)
176-
177-
disconnected: List[server.ServerConnection] = []
178-
179-
for client in clients_snapshot:
180-
try:
181-
if self._loop is not None:
182-
future = asyncio.run_coroutine_threadsafe(
183-
client.send(message), self._loop
184-
)
185-
future.result(timeout=self.CLIENT_SEND_TIMEOUT)
186-
except Exception as err:
187-
logger.warning("Failed to send to client: %s", err)
188-
disconnected.append(client)
189-
190-
for client in disconnected:
191-
self.remove_client(client)

tests/unit/test_broadcaster.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def test_start_sets_running_and_creates_thread(
7070

7171
assert broadcaster_instance._running is True
7272
assert broadcaster_instance._thread is not None
73-
assert broadcaster_instance._thread.is_alive()
7473
assert broadcaster_instance._thread.daemon is True
7574

7675
broadcaster_instance.stop()

0 commit comments

Comments
 (0)