I have an environment variable that allows a suite of applications to run under certain conditions, and the applications cannot run with the environment variable off.
My python script uses
p = subprocess.Popen(cmdStr3,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
to open the subprocess.
To test if the application is running, I have tried
try:
os.kill(pid, 0)
return True
except OSError:
return False
and also checking p.returncode. However, these always return true, because even if the application doesn't pull up on the screen, there are mini processes of ~1 MB that still run without the application fully running, so the os sees these and returns true. Is there a way around this?
Another issue is that os.kill doesn't work, the only way I have found to terminate the application is os.killpg at the end.
What I've learned from the comments is that what actually happens is that the subprocess I call is a starter that calls a child which is another application. My subprocess always runs, but with the environment variable off, the child application does not run. Is there a way to see if the child is running?
pidcan be found, the program exists and is running, right?p.terminate()to stop the child process andp.poll()to check if it is still running.ps, assuming those sub-child processes have a unique name. Otherwise, if the starter process doesn't keep track of the child, I think all bets are off (you could search for orphan processes, but there may be plenty).ps. For all the cases I've tested, the child application always has a process ID that is one more than the subprocess. Will this always be the case or is this a foolish way to check