def _write(self, bindata):
"""Write `bindata` to pipe in a gevent-cooperative manner.
POSIX-compliant system notes (http://linux.die.net/man/7/pipe:):
- Since Linux 2.6.11, the pipe capacity is 65536 bytes
- Relevant for large messages (O_NONBLOCK enabled,
n > PIPE_BUF (4096 Byte, usually)):
"If the pipe is full, then write(2) fails, with errno set
to EAGAIN. Otherwise, from 1 to n bytes may be written (i.e.,
a "partial write" may occur; the caller should check the
return value from write(2) to see how many bytes were
actually written), and these bytes may be interleaved with
writes by other processes."
EAGAIN is handled within _write_nonblocking; partial writes here.
"""
bindata = memoryview(bindata)
while True:
# Causes OSError when read end is closed (broken pipe).
bytes_written = _write_nonblocking(self._fd, bindata)
if bytes_written == len(bindata):
break
bindata = bindata[bytes_written:]
评论列表
文章目录