summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-10-08 04:00:35 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-10-08 04:00:35 +0000
commitde5b76ac5602c29c18351523df8f9990a0a67b5d (patch)
treeec1a0a277709ecb6001824fc04c06a319cdcdb58
parent1f789de5ded2eddc53fb4c57b9457e475e108537 (diff)
downloadpexpect-de5b76ac5602c29c18351523df8f9990a0a67b5d.tar.gz
Fix for Solaris -- it didn't return EOF after child's death.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@102 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/pexpect.py17
-rw-r--r--pexpect/pexqa.py10
-rwxr-xr-xpexpect/tests/test_destructor.py21
3 files changed, 36 insertions, 12 deletions
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index 99c4b1a..f934335 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -23,7 +23,7 @@ $Date$
"""
import os, sys
import select
-import signal
+# import signal
import traceback
import re
import struct
@@ -83,7 +83,6 @@ class spawn:
self.timeout = timeout
self.child_fd = -1
self.pid = None
- #self.log_fd = -1
self.log_file = None
self.before = None
self.after = None
@@ -104,7 +103,7 @@ class spawn:
Python only garbage collects Python objects. Since OS file descriptors
are not Python objects, so they must be handled manually.
"""
- if self.child_fd is not -1:
+ if self.child_fd != -1:
os.close (self.child_fd)
def __spawn(self):
@@ -374,7 +373,19 @@ class spawn:
This is a non-blocking wrapper around os.read().
It uses select.select() to supply a timeout.
+
"""
+ # Note that some systems like Solaris don't seem to ever give
+ # an EOF when the child dies. In fact, you can still try to read
+ # from the child_fd -- it will block forever or until TIMEOUT.
+ # For this case, I test isalive() before doing any reading.
+ # If isalive() is false, then I pretend that this is the same as EOF.
+ if not self.isalive():
+ r, w, e = select.select([self.child_fd], [], [], 0)
+ if not r:
+ self.flag_eof = 1
+ raise EOF ('End Of File (EOF) in read(). Braindead platform.')
+
r, w, e = select.select([self.child_fd], [], [], timeout)
if not r:
raise TIMEOUT('Timeout exceeded in read().')
diff --git a/pexpect/pexqa.py b/pexpect/pexqa.py
index 9e0f2fb..f3b23a4 100644
--- a/pexpect/pexqa.py
+++ b/pexpect/pexqa.py
@@ -17,10 +17,10 @@ class s:
self.pid = self.child_fd = None
try:
- self.pid, self.child_fd = posix.forkpty()
- #self.pid, self.child_fd = pty.fork()
+ #self.pid, self.child_fd = posix.forkpty()
+ self.pid, self.child_fd = pty.fork()
except OSError, e:
- raise Exception('posix.fork() failed: ' + str(e))
+ raise Exception('pty fork() failed: ' + str(e))
if self.pid == 0: # Child
os.execvp(command, args)
@@ -32,8 +32,8 @@ print '1'
x = s('ls', ['ls'])
time.sleep(5)
print '2'
-some = os.read (x.child_fd, 3225)
+result = os.read (x.child_fd, 5555)
print '3'
-print some
+print result
print '4'
diff --git a/pexpect/tests/test_destructor.py b/pexpect/tests/test_destructor.py
index e6c1d27..bc27d1f 100755
--- a/pexpect/tests/test_destructor.py
+++ b/pexpect/tests/test_destructor.py
@@ -2,6 +2,7 @@
import pexpect
import unittest
import gc
+import time
class TestCaseDestructor(unittest.TestCase):
#def runTest (self):
@@ -10,23 +11,35 @@ class TestCaseDestructor(unittest.TestCase):
p1 = pexpect.spawn('ls -l')
p2 = pexpect.spawn('ls -l')
p3 = pexpect.spawn('ls -l')
- fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd)
+ p4 = pexpect.spawn('ls -l')
+ fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+# print fd_t1
+ p1.kill(9);p2.kill(9);p3.kill(9);p4.kill(9)
p1 = None
p2 = None
p3 = None
+ p4 = None
gc.collect()
+ time.sleep(3) # Some platforms are slow at gc... Solaris!
p1 = pexpect.spawn('ls -l')
p2 = pexpect.spawn('ls -l')
p3 = pexpect.spawn('ls -l')
- fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd)
+ p4 = pexpect.spawn('ls -l')
+ fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+# print fd_t2
+ p1.kill(9);p2.kill(9);p3.kill(9);p4.kill(9)
del (p1)
- del (p3)
del (p2)
+ del (p3)
+ del (p4)
gc.collect()
+ time.sleep(3) # Some platforms are slow at gc... Solaris!
p1 = pexpect.spawn('ls -l')
p2 = pexpect.spawn('ls -l')
p3 = pexpect.spawn('ls -l')
- fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd)
+ p4 = pexpect.spawn('ls -l')
+ fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+# print fd_t3
assert (fd_t1 == fd_t2 == fd_t3)