- if (flags & socket.MSG_DONTWAIT) == 0:
- select.select([self.proc.stdout], [], [])
- return self.proc.stdout.read(buflen)
+ while len(self.inbuf) == 0:
+ try:
+ rv = os.read(self.proc.stdout.fileno(), max(4096, buflen))
+ except BlockingIOError:
+ if flags & socket.MSG_DONTWAIT:
+ raise
+ select.select([self.proc.stdout], [], [])
+ else:
+ self.inbuf.extend(rv)
+ rv = bytes(self.inbuf[:buflen])
+ self.inbuf[:buflen] = b""
+ return rv