I wrote a python script that's responsible for executing other scripts. I do notice that every now and then, I get a defunct process.
I was reading some other threads on StackOverFlow and they said that you can catch a problem if .communicate
or .call
aren't used.
The only thing I'm struggling with now is that I need to also get the exit code of the process.
My code is below.
job.append("py")
job.append("\tmp\test\sleep.py")
job.append("20")
p = subprocess.Popen(job, stderr=subprocess.PIPE,stdout=subprocess.PIPE)
exit_code_main = p.wait()
I need to get all output from the execution of the subprocess and I need to get the error output if there is any. The exit code is what I use to determine if the script in the subprocess executed successfully.