Spaces:
Running
Running
siddhm11
Claude Opus 5.5
fix(ingest): hard deadlines on network calls, stack dumps, ingest timeout
e1e1d27 Download scripts/net_deadline.py from siddhm11/ResearchIT: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/siddhm11/ResearchIT/resolve/main/scripts/net_deadline.py
- Command line
-
hf download hf://spaces/siddhm11/ResearchIT/scripts/net_deadline.py
-
curl -L -o net_deadline.py https://huggingface.co/spaces/siddhm11/ResearchIT/resolve/main/scripts/net_deadline.py
1.32 kB
| """A hard wall-clock limit for one blocking network call. | |
| Socket timeouts bound each individual read, not the request: a server that | |
| trickles bytes, or a library call made without a timeout, can block forever. | |
| On 2026-10-01 a daily-refresh ingest sat 20 minutes at 0% CPU in an SSL read | |
| (_buffered_readline -> SSLSocket.read -> poll) while arXiv answered other | |
| requests in 0.2 s. SIGALRM interrupts a blocked syscall, and the handler's | |
| exception aborts the call instead of letting it resume. | |
| Main thread only (where the ingest makes all its requests); elsewhere it is a | |
| no-op rather than an error. | |
| """ | |
| from __future__ import annotations | |
| import contextlib | |
| import signal | |
| import threading | |
| class DeadlineExceeded(TimeoutError): | |
| pass | |
| def deadline(seconds: float, what: str = "network call"): | |
| if (seconds <= 0 or not hasattr(signal, "SIGALRM") | |
| or threading.current_thread() is not threading.main_thread()): | |
| yield | |
| return | |
| def _expire(_signum, _frame): | |
| raise DeadlineExceeded(f"{what} exceeded {seconds:.0f}s") | |
| previous = signal.signal(signal.SIGALRM, _expire) | |
| signal.setitimer(signal.ITIMER_REAL, seconds) | |
| try: | |
| yield | |
| finally: | |
| signal.setitimer(signal.ITIMER_REAL, 0) | |
| signal.signal(signal.SIGALRM, previous) | |