def read(self, size=1):
        if not self.is_open:
            raise portNotOpenError
        read = bytearray()
        timeout = self._timeout
        while len(read) < size:
            try:
                start_time = time.time()
                ready, _, _ = select.select([self._socket], [], [], timeout)
                # If select was used with a timeout, and the timeout occurs, it
                # returns with empty lists -> thus abort read operation.
                # For timeout == 0 (non-blocking operation) also abort when
                # there is nothing to read.
                if not ready:
                    break   # timeout
                buf = self._socket.recv(size - len(read))
                # read should always return some data as select reported it was
                # ready to read when we get to this point, unless it is EOF
                if not buf:
                    raise SerialException('socket disconnected')
                read.extend(buf)
                if timeout is not None:
                    timeout -= time.time() - start_time
                    if timeout <= 0:
                        break
            except socket.timeout:
                # timeout is used for write support, just go reading again
                pass
            except socket.error as e:
                # connection fails -> terminate loop
                raise SerialException('connection failed ({})'.format(e))
            except OSError as e:
                # this is for Python 3.x where select.error is a subclass of
                # OSError ignore EAGAIN errors. all other errors are shown
                if e.errno != errno.EAGAIN:
                    raise SerialException('read failed: {}'.format(e))
            except select.error as e:
                # this is for Python 2.x
                # ignore EAGAIN errors. all other errors are shown
                # see also http://www.python.org/dev/peps/pep-3151/#select
                if e[0] != errno.EAGAIN:
                    raise SerialException('read failed: {}'.format(e))
        return bytes(read)
Read size bytes from the serial port. If a timeout is set it may
dataset/ETHPy150Open pyserial/pyserial/serial/urlhandler/protocol_socket.py/Serial.read