facebook/tornado — pull request #851 by bendyer (2013-07-12 06:43:04+00:00)
Title: Correctly handle EAGAIN when writing to PipeIOStreams

`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 raise `socket.error` when the buffer is full.

The problem is demonstrated by the added test case, `TestPipeIOStream.test_pipe_iostream_big_write`.

Without the change, `TestPipeIOStream.test_pipe_iostream_big_write` fails with the following error:

======================================================================
ERROR: test_pipe_iostream_big_write (tornado.test.iostream_test.TestPipeIOStream)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tornado/test/iostream_test.py", line 556, in test_pipe_iostream_big_write
ws.write(b"1" * NUM_BYTES)
File "tornado/iostream.py", line 228, in write
self._handle_write()
File "tornado/iostream.py", line 550, in _handle_write
num_bytes = self.write_to_fd(self._write_buffer[0])
File "tornado/iostream.py", line 963, in write_to_fd
return os.write(self.fd, data)
OSError: [Errno 35] Resource temporarily unavailable

----------------------------------------------------------------------

This change to the exceptions handled by `BaseIOStream._handle_write` provides consistency with the exceptions caught by `BaseIOStream._read_to_buffer`.