[Python-Dev] Functionality in subprocess.Popen.terminate() (original) (raw)

Eric Pruitt eric.pruitt at gmail.com
Tue Aug 4 17:01:57 CEST 2009


On Tue, Aug 4, 2009 at 04:27, Nick Coghlan<ncoghlan at gmail.com> wrote:

Eric Pruitt wrote:

In my GSoC project, I have implemented asnychronous I/O in subprocess.Popen. Since the read/write operations are asynchronous, the program may have already exited by the time one calls the asyncread function I have implemented. While it returns the data just fine, I have come across an issue with the TerminateProcess function in Windows: if the program has already exited, when subprocess.Popen.Terminate calls the Windows built-in "TerminateProcess" function, an "access denied" error will occur. Should I just make it so that this exception is simply ignored or perform some kind of check to see if the process exists beforehand? If the latter, I have been unable to find a way to do so, to my liking at least. The solutions I saw would require code that seems a bit excessive to me. I'm pretty sure we already ignore some spurious error messages in cases like calling flush() in file.close(). I would suggest checking what the io module does in such cases and see what kind of precedent it sets. Cheers, Nick. -- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia ---------------------------------------------------------------

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.

Eric



More information about the Python-Dev mailing list