I'm having a hard time getting what I want out of the python subprocess module (which supposed to an unified/platform-independent abstraction, afaik, but don't get me started on that :)).
So the simple thing what I'm after is the following. I want to
Now, my main problems are that
I hope I was specific enough. Thanks for any tips/hints in advance -- I just spent a whole day with subprocess, and IMHO it's a pain far from either platform-independent or simple :( (but perhaps it's just me)
UPDATE (2010-10-13):
If you launch a sub-process (even with shell=False), then the subprocess.Popen.kill() function will only kill that sub-process (so if there are any "grandchild" processes, they won't be terminated.)
I read about using the preexec_fn parameter to set the sid on all child processes, but it's unix-only: timeout a subprocess
Last time I was in a similar situation, I found out the easiest (and practically the only) solution was to kick off a thread which takes care of your child process. You can take different routes with this method, be it to parse the piping of the shell-style command and perform those in python code (which you said wasn't an option due to the blocking), which would at the same time fix your killing problem. Basically, thread encapsulation seems like the way to go.
Sadly my experience with subprocess
is all on the Windows platform, which has tons of its own little quirks. subprocess
has a lot of flaws all-around it seems, although it must do an okay job given the existence of the popen
, popen2
and so forth modules that it is supposed to replace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With