def _partial_flush(self, max_retain):
        byts = self._bd.get_all()
        cursor = buffer(byts)

        flushed = False
        while len(cursor) > max_retain:
            try:
                n = os.write(self._fd, cursor)
                flushed = True
                cursor = buffer(cursor, n)
            except EnvironmentError, e:
                if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
                    gevent.socket.wait_write(self._fd)
                else:
                    raise

        assert self._bd.byteSz == 0
        if len(cursor) > 0:
            self._bd.add(cursor)

        return flushed
dataset/ETHPy150Open wal-e/wal-e/wal_e/pipebuf.py/NonBlockBufferedWriter._partial_flush/original