summaryrefslogtreecommitdiff
path: root/pexpect/fdpexpect.py
diff options
context:
space:
mode:
authorDavid Cullen <david.cullen@technicolor.com>2016-06-28 14:49:43 -0400
committerDavid Cullen <david.cullen@technicolor.com>2016-06-28 14:49:43 -0400
commit7c03f4746c06cdfa169b514f38f856dc4caa263f (patch)
treee524a921ecb320d29c27172f045f944c628cf00e /pexpect/fdpexpect.py
parent3ed8d66ffb12863bc4a55a4b5dab7fca7ce9a9cc (diff)
downloadpexpect-7c03f4746c06cdfa169b514f38f856dc4caa263f.tar.gz
Restore POSIX support to fdpexpect.
Diffstat (limited to 'pexpect/fdpexpect.py')
-rw-r--r--pexpect/fdpexpect.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pexpect/fdpexpect.py b/pexpect/fdpexpect.py
index dd1b492..25b5c8d 100644
--- a/pexpect/fdpexpect.py
+++ b/pexpect/fdpexpect.py
@@ -22,7 +22,8 @@ PEXPECT LICENSE
'''
from .spawnbase import SpawnBase
-from .exceptions import ExceptionPexpect
+from .exceptions import ExceptionPexpect, TIMEOUT
+from .utils import select_ignore_interrupts
import os
__all__ = ['fdspawn']
@@ -112,3 +113,19 @@ class fdspawn(SpawnBase):
"Call self.write() for each item in sequence"
for s in sequence:
self.write(s)
+
+ def read_nonblocking(self, size=1, timeout=-1):
+ '''The read_nonblocking method of fdspawn assumes that the file
+ will never block. This is not the case for all file like objects
+ that support fileno (e.g. POSIX sockets and serial ports). So we
+ use select to implement the timeout on POSIX.'''
+ if os.name == 'posix':
+ if timeout == -1:
+ timeout = self.timeout
+ rlist = [self.child_fd]
+ wlist = []
+ xlist = []
+ rlist, wlist, xlist = select_ignore_interrupts(rlist, wlist, xlist, timeout)
+ if self.child_fd not in rlist:
+ raise TIMEOUT('Timeout exceeded.')
+ return super(fdspawn, self).read_nonblocking(size)