MCPcopy Create free account
hub / github.com/1jehuang/jcode / read_events

Function read_events

scripts/jcode_monitor.py:83–107  ·  view source on GitHub ↗

Read available events from socket (non-blocking)

(sock: socket.socket)

Source from the content-addressed store, hash-verified

81
82
83def read_events(sock: socket.socket) -> list:
84 """Read available events from socket (non-blocking)"""
85 events = []
86 buffer = ""
87
88 try:
89 while True:
90 data = sock.recv(4096)
91 if not data:
92 break
93 buffer += data.decode()
94
95 while "\n" in buffer:
96 line, buffer = buffer.split("\n", 1)
97 if line.strip():
98 try:
99 events.append(json.loads(line))
100 except json.JSONDecodeError:
101 pass
102 except BlockingIOError:
103 pass
104 except:
105 pass
106
107 return events
108
109
110def format_tokens(n: int) -> str:

Callers 1

mainFunction · 0.70

Calls 3

recvMethod · 0.80
decodeMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected