BaseIOStream._handle_write needs to catch IOError and OSError as
well as socket.error in order to handle EAGAIN when writing to a
PipeIOStream (which doesn't appear to raise socket.error when the
buffer is full).
This also provides consistency with the exceptions caught by
BaseIOStream._read_to_buffer.
self._write_buffer_frozen = False
_merge_prefix(self._write_buffer, num_bytes)
self._write_buffer.popleft()
- except socket.error as e:
+ except (socket.error, IOError, OSError) as e:
if e.args[0] in _ERRNO_WOULDBLOCK:
self._write_buffer_frozen = True
break
self.assertEqual(data, b"ld")
rs.close()
+
+ def test_pipe_iostream_big_write(self):
+ r, w = os.pipe()
+
+ rs = PipeIOStream(r, io_loop=self.io_loop)
+ ws = PipeIOStream(w, io_loop=self.io_loop)
+
+ NUM_BYTES = 1048576
+
+ # Write 1MB of data, which should fill the buffer
+ ws.write(b"1" * NUM_BYTES)
+
+ rs.read_bytes(NUM_BYTES, self.stop)
+ data = self.wait()
+ self.assertEqual(data, b"1" * NUM_BYTES)
+
+ ws.close()
+ rs.close()