def write(self, data):
        """Output the given byte string over the serial port."""
        if not self.is_open:
            raise portNotOpenError
        d = to_bytes(data)
        tx_len = len(d)
        timeout = self._write_timeout
        if timeout and timeout > 0:   # Avoid comparing None with zero
            timeout += time.time()
        while tx_len > 0:
            try:
                n = os.write(self.fd, d)
                if timeout == 0:
                    # Zero timeout indicates non-blocking - simply return the
                    # number of bytes of data actually written
                    return n
                elif timeout and timeout > 0:  # Avoid comparing None with zero
                    # when timeout is set, use select to wait for being ready
                    # with the time left as timeout
                    timeleft = timeout - time.time()
                    if timeleft < 0:
                        raise writeTimeoutError
                    _, ready, _ = select.select([], [self.fd], [], timeleft)
                    if not ready:
                        raise writeTimeoutError
                else:
                    assert timeout is None
                    # wait for write operation
                    _, ready, _ = select.select([], [self.fd], [], None)
                    if not ready:
                        raise SerialException('write failed (select)')
                d = d[n:]
                tx_len -= n
            except SerialException:
                raise
            except __HOLE__ as v:
                if v.errno != errno.EAGAIN:
                    raise SerialException('write failed: {}'.format(v))
                # still calculate and check timeout
                if timeout and timeout - time.time() < 0:
                    raise writeTimeoutError
        return len(data)
dataset/ETHPy150Open pyserial/pyserial/serial/serialposix.py/Serial.write