MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / _run

Method _run

masfactory/visualizer/runtime.py:651–799  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

649 return self._subscribed
650
651 def _run(self) -> None:
652 last_hb = 0.0
653 reconnect_delay = 0.25
654
655 while not self._stop.is_set():
656 try:
657 with self._lock:
658 host = self._host
659 port = self._port
660 mode = self._mode
661 graph_name = self._graph_name or "unknown"
662 sock = socket.create_connection((host, port), timeout=3)
663 try:
664 ws_handshake(sock, host, port)
665 sock.settimeout(0.05)
666 with self._lock:
667 self._connected = True
668
669 ws_send_text(
670 sock,
671 json.dumps(
672 {"type": "HELLO", "pid": self._pid, "graphName": graph_name, "mode": mode}
673 ),
674 )
675
676 buf = b""
677 last_hb = 0.0
678 self._subscribed = False
679 reconnect_delay = 0.25
680
681 while not self._stop.is_set():
682 now = time.time()
683
684 # Heartbeat (always)
685 if now - last_hb >= 0.5:
686 with self._lock:
687 graph_name = self._graph_name or "unknown"
688 mode = self._mode
689 ws_send_text(
690 sock,
691 json.dumps(
692 {
693 "type": "HEARTBEAT",
694 "pid": self._pid,
695 "graphName": graph_name,
696 "mode": mode,
697 }
698 ),
699 )
700 last_hb = now
701
702 # Send queued messages
703 for msg in self._drain_outq():
704 ws_send_text(sock, json.dumps(msg, ensure_ascii=False, default=str))
705
706 # Send graph lazily (run mode on subscribe; debug mode always)
707 with self._lock:
708 gv = self._graph_version

Callers

nothing calls this directly

Calls 11

_drain_outqMethod · 0.95
ws_handshakeFunction · 0.85
ws_send_textFunction · 0.85
ws_try_decode_frameFunction · 0.85
WebSocketErrorClass · 0.85
ws_send_pongFunction · 0.85
_as_strFunction · 0.85
ws_send_closeFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected