Wait for the ready signal from the subprocess, checking for early death.
(sync_sock, process, timeout)
| 218 | |
| 219 | |
| 220 | def _wait_for_ready_signal(sync_sock, process, timeout): |
| 221 | """Wait for the ready signal from the subprocess, checking for early death.""" |
| 222 | deadline = time.monotonic() + timeout |
| 223 | sel = selectors.DefaultSelector() |
| 224 | sel.register(sync_sock, selectors.EVENT_READ) |
| 225 | |
| 226 | try: |
| 227 | while True: |
| 228 | _check_process_died(process) |
| 229 | |
| 230 | remaining = deadline - time.monotonic() |
| 231 | if remaining <= 0: |
| 232 | raise socket.timeout("timed out") |
| 233 | |
| 234 | if not sel.select(timeout=min(0.1, remaining)): |
| 235 | continue |
| 236 | |
| 237 | conn, _ = sync_sock.accept() |
| 238 | try: |
| 239 | ready_signal = conn.recv(_RECV_BUFFER_SIZE) |
| 240 | finally: |
| 241 | conn.close() |
| 242 | |
| 243 | if ready_signal != _READY_MESSAGE: |
| 244 | raise RuntimeError(f"Invalid ready signal received: {ready_signal!r}") |
| 245 | return |
| 246 | finally: |
| 247 | sel.close() |
| 248 | |
| 249 | |
| 250 | def _run_with_sync(original_cmd, suppress_output=False): |
no test coverage detected
searching dependent graphs…