From 79c071275208f0680ddcabd310b065ca7ec8f405 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 24 Oct 2013 16:42:24 -0700 Subject: [PATCH] Catch failures reading data from terminated subprocesses --- IPython/testing/iptest.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index d062268ce..e94540a04 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: