subprocess module is sorely deficient?

Paul Boddie paul at boddie.org.uk
Tue Apr 22 07:36:26 EDT 2008


On 22 Apr, 12:52, Harishankar <v.harishan... at gmail.com> wrote:
>
> Is there any way to use non-blocking Popen objects using subprocess? and 2 -
> is there a way to kill the subprocess in a platform independent manner in a
> purely Pythonic way? I thought initially that this problem is simple enough,
> but over the last couple of days I've been really struggling to find any
> answer. I've been through dozens of mailing list archives in to find a
> solution. Unfortunately none of the solutions seem to fit my needs.

If you want some hints about using subprocesses with non-blocking I/O,
you might find some in my jailtools and pprocess projects:

http://www.python.org/pypi/jailtools
http://www.python.org/pypi/pprocess

Although these projects involve things which are not exactly cross-
platform, the communications mechanisms should be portable, perhaps
with a bit of effort (since I don't recall whether the poll library
function is available on Windows, so you might have to use the select
function instead). It can be awkward sustaining non-blocking
communications with processes if they use buffered I/O, and the only
way I could make Python-based subprocesses work in jailtools was to
invoke them with the unbuffered option (-u).

> My only solution seems to be to offer the end user the mencoder command line
> and make them execute it manually and be done with it but that seems a rather
> weak solution.

The subprocess module may be an improvement over the popen2 module and
various os module functions, but it's still rather arcane.

Paul



More information about the Python-list mailing list