summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-10-22 03:47:19 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-10-22 03:47:19 +0000
commit99926edeca18b2f324e5b8329814fc604f4860da (patch)
treec4bf4cedcf97047e831e843b22fb9bd938dc667d
parent930eda316b824671b4c83318484f9c9a16922e68 (diff)
downloadpexpect-99926edeca18b2f324e5b8329814fc604f4860da.tar.gz
I think Solaris may be screwed...
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@112 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/Makefile2
-rw-r--r--pexpect/pexpect.py28
-rw-r--r--pexpect/setup.py2
-rwxr-xr-xpexpect/tests/test_isalive.py13
4 files changed, 33 insertions, 12 deletions
diff --git a/pexpect/Makefile b/pexpect/Makefile
index e0c0811..ce23140 100644
--- a/pexpect/Makefile
+++ b/pexpect/Makefile
@@ -1,6 +1,6 @@
SHELL = /bin/sh
-VERSION= 0.93
+VERSION= 0.94
#DOCGENERATOR= happydoc
DOCGENERATOR= pydoc -w
MANIFEST_LINES != cat MANIFEST
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index 1e75191..850a1ee 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -468,21 +468,37 @@ class spawn:
def isalive(self):
"""This tests if the child process is running or not.
This returns 1 if the child process appears to be running or 0 if not.
+ I can't figure out how to check if a process is alive on Solaris.
+ This is what is wrong. Apparently the call:
+ os.waitpid(self.pid, os.WNOHANG)
+ does not work. It always returns with (0,0) whether the process
+ is running or defunct. This works:
+ os.waitpid(self.pid, 0)
+ but it blocks if the process IS alive, so it's useless for me.
+ I don't want to use signals. Signals on UNIX suck and they
+ mess up Python pipes (setting SIGCHLD to SIGIGNORE).
"""
try:
- status = os.waitpid (self.pid, os.WNOHANG)
+ pid, status = os.waitpid(self.pid, os.WNOHANG)
except OSError, e:
return 0
-
- if status[0] == 0:
+### This does not work on Solaris. Grrr!!!
+# if pid == self.pid and status == 0:
+ if status == 0:
return 1
+# if pid == 0 and status == 0: # This happens on Solaris...
+# # This means (I think) that the Solaris process is "defunct"
+# # and a second wait must be called without the WNOHANG.
+# # This is dangerous because if I am wrong then this could block.
+# pid, status = os.waitpid (self.pid, 0)
+
# I didn't OR this together because I want hooks for debugging.
- if os.WIFEXITED (status[1]):
+ if os.WIFEXITED (status):
return 0
- elif os.WIFSTOPPED (status[1]):
+ elif os.WIFSTOPPED (status):
return 0
- elif os.WIFSIGNALED (status[1]):
+ elif os.WIFSIGNALED (status):
return 0
else:
return 1
diff --git a/pexpect/setup.py b/pexpect/setup.py
index a9ccf05..b20824e 100644
--- a/pexpect/setup.py
+++ b/pexpect/setup.py
@@ -4,7 +4,7 @@ $Date$
'''
from distutils.core import setup
setup (name='pexpect',
- version='0.93',
+ version='0.94',
py_modules=['pexpect'],
description='Pexpect, a pure Python Expect allows control of other applications.',
author='Noah Spurrier',
diff --git a/pexpect/tests/test_isalive.py b/pexpect/tests/test_isalive.py
index c678e05..0ba7b41 100755
--- a/pexpect/tests/test_isalive.py
+++ b/pexpect/tests/test_isalive.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import pexpect
import unittest
-import sys
+import sys, os
class IsAliveTestCase(unittest.TestCase):
@@ -12,7 +12,7 @@ class IsAliveTestCase(unittest.TestCase):
self.fail ('Child process is not dead. It should be.')
def test_expect_isalive2 (self):
- p = pexpect.spawn('cat')
+ p = pexpect.spawn('cat', timeout=5)
if not p.isalive():
self.fail ('Child process is not alive. It should be.')
p.kill(1)
@@ -21,15 +21,20 @@ class IsAliveTestCase(unittest.TestCase):
self.fail ('Child process is not dead. It should be.')
def test_expect_isalive3 (self):
- p = pexpect.spawn('cat')
+ p = pexpect.spawn('cat', timeout=3)
if not p.isalive():
self.fail ('Child process is not alive. It should be.')
p.kill(9)
p.expect(pexpect.EOF)
if p.isalive():
+# pid, sts = os.waitpid(p.pid, 0)#, os.WNOHANG)
+# print 'p.pid, pid, sts:', p.pid, pid, sts
+# pp = pexpect.spawn('ps -p %d' % p.pid)
+# pp.expect (pexpect.EOF)
+# print pp.before
self.fail ('Child process is not dead. It should be.')
-# Some platforms allow this. Some reset status after call to waitpid.
+### Some platforms allow this. Some reset status after call to waitpid.
def OFF_test_expect_isalive4 (self):
"""This tests that multiple calls to isalive() return same value.
"""