Eric Pruitt wrote:
Sounds good enough to me but I was wondering if it might be a good idea to add a function like "pidinuse" to subprocess as a whole that would determine if a process ID was being used and return a simple boolean value. I came across a number of people searching for a way to determine if a PID was running (Google "python check if pid exists") so it seems like the implemented functionality would be of use to the community as a whole, not just my wrapper class.
I'm not sure of the actual details but it seems from your description that even if you check first a race condition will still exist. Specifically the subprocess could terminate after the check and before the TerminateProcess call. So it seems better just to call TerminateProcess and then correctly handle any possible error.
Janzert is correct here - this is a case where ruling out the error completely is impossible, so you're going to have to handle it regardless.
A cross platform way of checking if a particular subprocess is still running might be an interesting feature in its own right, but I don't think it will prevent this exception.