469,904 Members | 2,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

subprocess returncode always None

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
Jul 9 '06 #1
0 1933

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Christoph Haas | last post: by
4 posts views Thread by 7stud | last post: by
12 posts views Thread by bhunter | last post: by
3 posts views Thread by jakub.hrozek | last post: by
reply views Thread by Albert Hopkins | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.