_try_read: hacky fix to make GNU make less angry.

We'll have to stop using nonblocking reads, unfortunately.  But this seems
to work better than nothing.  There's still a race condition that could
theoretically make GNU make angry, unfortunately, since we briefly set the
socket to nonblocking.
This commit is contained in:
Avery Pennarun 2010-11-13 04:50:03 -08:00
commit 662f53896a

View file

@ -32,14 +32,20 @@ def _release(n):
def _try_read(fd, n): def _try_read(fd, n):
# FIXME: this isn't actually safe, because GNU make can't handle it if
# the socket is nonblocking. Ugh. That means we'll have to do their
# horrible SIGCHLD hack after all.
fcntl.fcntl(_fds[0], fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(_fds[0], fcntl.F_SETFL, os.O_NONBLOCK)
try: try:
b = os.read(_fds[0], 1) # FIXME try: block try:
except OSError, e: b = os.read(_fds[0], 1)
if e.errno == errno.EAGAIN: except OSError, e:
return '' if e.errno == errno.EAGAIN:
else: return ''
raise else:
raise
finally:
fcntl.fcntl(_fds[0], fcntl.F_SETFL, 0)
return b and b or None return b and b or None