Skip to content

Commit

Permalink
Set ping_interval on WebSocket connection (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4victor authored Oct 30, 2024
1 parent 4330c3f commit 3858b8a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dstack/api/_public/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ def _attached_logs(
def ws_thread():
try:
logger.debug("Starting WebSocket logs for %s", self.name)
ws.run_forever()
ws.run_forever(ping_interval=60)
finally:
logger.debug("WebSocket logs are done for %s", self.name)
q.put(_done)

ws = WebSocketApp(
f"ws://localhost:{self.ports[10999]}/logs_ws",
on_open=lambda _: logger.debug("WebSocket logs are connected to %s", self.name),
on_close=lambda _, __, ___: logger.debug("WebSocket logs are disconnected"),
on_close=lambda _, status_code, msg: logger.debug(
"WebSocket logs are disconnected. status_code: %s; message: %s",
status_code,
msg,
),
on_message=lambda _, message: q.put(message),
)
threading.Thread(target=ws_thread).start()
Expand Down

0 comments on commit 3858b8a

Please sign in to comment.