MCPcopy Index your code
hub / github.com/python/cpython / _wait_for_n_signals

Function _wait_for_n_signals

Lib/test/test_external_inspection.py:126–163  ·  view source on GitHub ↗

Wait for N occurrences of a signal pattern. Args: sock: Connected socket to read from signal_pattern: bytes pattern to count (e.g., b"ready") count: Number of occurrences expected timeout: Socket timeout in seconds Returns: bytes: Complete accum

(sock, signal_pattern, count, timeout=SHORT_TIMEOUT)

Source from the content-addressed store, hash-verified

124
125
126def _wait_for_n_signals(sock, signal_pattern, count, timeout=SHORT_TIMEOUT):
127 """
128 Wait for N occurrences of a signal pattern.
129
130 Args:
131 sock: Connected socket to read from
132 signal_pattern: bytes pattern to count (e.g., b"ready")
133 count: Number of occurrences expected
134 timeout: Socket timeout in seconds
135
136 Returns:
137 bytes: Complete accumulated response buffer
138
139 Raises:
140 RuntimeError: If connection closed or timeout before receiving all signals
141 """
142 sock.settimeout(timeout)
143 buffer = b""
144 found_count = 0
145
146 while found_count < count:
147 try:
148 chunk = sock.recv(4096)
149 if not chunk:
150 raise RuntimeError(
151 f"Connection closed after {found_count}/{count} signals. "
152 f"Last 200 bytes: {buffer[-200:]!r}"
153 )
154 buffer += chunk
155 # Count occurrences in entire buffer
156 found_count = buffer.count(signal_pattern)
157 except socket.timeout:
158 raise RuntimeError(
159 f"Timeout waiting for {count} signals (found {found_count}). "
160 f"Last 200 bytes: {buffer[-200:]!r}"
161 )
162
163 return buffer
164
165
166@contextmanager

Callers 1

Calls 3

settimeoutMethod · 0.45
recvMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…