def _winread(self, size, timeout):
        t0 = time.time()
        buf = ''
        if timeout is None or timeout == -1:
            timeout = 30
        while len(buf) < size:
            try:
                incoming = self._read_queue.get(True, 1e-3)
            except Queue.Empty:
                break
            except KeyboardInterrupt:
                self.sendintr()
                break
            else:
                if not incoming:
                    self.flag_eof = True
                    raise EOF('End of File')

                buf += incoming

            if (time.time() - t0) >= timeout:
                break

        if len(buf) > size:
            self.buffer = buf[size:]
            buf = buf[:size]

        buf = self._coerce_read_string(buf)
        self._log(buf, 'read')
        return buf
dataset/ETHPy150Open Calysto/metakernel/metakernel/pexpect.py/spawn._winread/original