From 662f53896ab05ab753049cbf2e0eac054079c938 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Sat, 13 Nov 2010 04:50:03 -0800 Subject: [PATCH] _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. --- jwack.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/jwack.py b/jwack.py index ab0e2f5..00df9be 100755 --- a/jwack.py +++ b/jwack.py @@ -32,14 +32,20 @@ def _release(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) try: - b = os.read(_fds[0], 1) # FIXME try: block - except OSError, e: - if e.errno == errno.EAGAIN: - return '' - else: - raise + try: + b = os.read(_fds[0], 1) + except OSError, e: + if e.errno == errno.EAGAIN: + return '' + else: + raise + finally: + fcntl.fcntl(_fds[0], fcntl.F_SETFL, 0) return b and b or None