diff --git a/redo/jobserver.py b/redo/jobserver.py index 800f5d3..86eea3c 100644 --- a/redo/jobserver.py +++ b/redo/jobserver.py @@ -142,8 +142,10 @@ def release_mine(): _release(1) +class TimeoutError(Exception): pass + def _timeout(sig, frame): - pass + raise TimeoutError() # We make the pipes use the first available fd numbers starting at startfd. @@ -171,11 +173,13 @@ def _try_read(fd, n): return None # try again # ok, the socket is readable - but some other process might get there # first. We have to set an alarm() in case our read() gets stuck. - oldh = signal.signal(signal.SIGALRM, _timeout) try: + oldh = signal.signal(signal.SIGALRM, _timeout) signal.setitimer(signal.ITIMER_REAL, 0.01, 0.01) # emergency fallback try: b = os.read(fd, 1) + except TimeoutError: + return None # try again except OSError as e: if e.errno in (errno.EAGAIN, errno.EINTR): # interrupted or it was nonblocking