def write(self, data):
        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 OSError 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)
Test if it runs the Django-Admin syncdb command
dataset/ETHPy150Open pyserial/pyserial/serial/serialposix.py/Serial.write--crossover with--dataset/ETHPy150Open saltstack/salt/tests/unit/modules/djangomod_test.py/DjangomodTestCase.test_syncdb