Skip to content

Commit

Permalink
Merge pull request tornadoweb#851 from taguchimail/master
Browse files Browse the repository at this point in the history
Correctly handle EAGAIN when writing to PipeIOStreams
  • Loading branch information
bdarnell committed Jul 16, 2013
2 parents e4e93e9 + 11236e7 commit 191972b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tornado/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def _handle_write(self):
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
Expand Down
18 changes: 18 additions & 0 deletions tornado/test/iostream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,21 @@ def test_pipe_iostream(self):
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()

0 comments on commit 191972b

Please sign in to comment.