New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes serialposix.Serial.write() respect non-blocking #97

merged 1 commit into from Mar 26, 2016
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+9 −5
Diff settings


Just for now

Copy path View file
@@ -521,14 +521,17 @@ def write(self, data):
raise portNotOpenError
d = to_bytes(data)
tx_len = len(d)
if self._write_timeout is not None and self._write_timeout > 0:
timeout = time.time() + self._write_timeout
timeout = None
timeout = self._write_timeout
if timeout and timeout > 0: # Avoid comparing None with zero
timeout += time.time()
while tx_len > 0:
n = os.write(self.fd, d)
if timeout:
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()
@@ -538,6 +541,7 @@ def write(self, data):
if not ready:
raise writeTimeoutError
assert timeout is None
# wait for write operation
_, ready, _ =[], [self.fd], [], None)
if not ready:
ProTip! Use n and p to navigate between commits in a pull request.