From e50eefd86b3108514e2574b1db83da10f9be8d11 2013-10-29 16:15:56 From: Thomas Kluyver Date: 2013-10-29 16:15:56 Subject: [PATCH] Catch failures reading data from terminated subprocesses --- diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index d062268..e94540a 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -382,9 +382,21 @@ class StreamCapturer(Thread): continue ready = select(streams, [], [], 0.5)[0] + dead = [] with self.buffer_lock: for fd in ready: - self.buffer.write(os.read(fd, 1024)) + try: + self.buffer.write(os.read(fd, 1024)) + except OSError as e: + import errno + if e.errno == errno.EBADF: + dead.append(fd) + else: + raise + + with self.streams_lock: + for fd in dead: + self.streams.remove(fd) def add_stream(self, fd): with self.streams_lock: