subprocess returncode always None

C

Corey Wallis

Dear All,

I'm currently working on a project that needs to collect the output of
the JHOVE application. More information about the application is
available at this website:

http://hul.harvard.edu/jhove/

The application is written in Java and is executed by a shell script.
There are occasions where this application may get stuck in an
infinite loop. For this reason I've been trying to implement a simple
class that I can use to execute the JHOVE application and if it
doesn't complete in the required period of time to raise an exception
and kill the process.

The class is as follows, apologies for the odd line wrapping.

<snip>
class niceSubprocess(object):
"""
A class that implements a call to the subprocess method with a timeout
- command, the command to execute
- params, the parameters to pass to the application
- timeout, the amount of time in seconds to wait
"""
def executeCommand(self, command, params, timeout):
try:
timeElapsed = 0

process = subprocess.Popen((command, params), stdin =
subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE,
close_fds = True)

while process.poll() == None and timeElapsed < timeout:
print process.poll()
#print process.stdout.read()
timeElapsed = timeElapsed + 1
time.sleep(1)

if process.poll() == None:
# kill off the process, and don't be terribly nice about it
os.kill(process.pid, signal.SIGKILL)
raise timeoutError, timeout
else:
if process.stdout.read() == "":
raise executeError, process.stderr.read()
else:
return process.stdout.read()

except Exception, errorInfo:
# pass the exception to the calling code
raise errorInfo

</snip>

I'm running this on Linux and through the use of top can see the JAVA
process start and complete. The problem I have is that process.poll()
always returns None, even though the application has successfully ran
and returned output.

Can anyone shed some light on why the call to the shell script always
returns None as a return code?

With thanks.

-Corey

--
Corey Wallis
RUBRIC Technical Officer
University of Southern Queensland
http://www.rubric.edu.au
http://techxplorer.wordpress.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top