[Python 2.4/2.5] subprocess module is sorely deficient?

Nick Craig-Wood nick at craig-wood.com
Tue Apr 22 16:30:03 EDT 2008


Mark Wooding <mdw at distorted.org.uk> wrote:
>  Nick Craig-Wood <nick at craig-wood.com> wrote:
> > Harishankar <v.harishankar at gmail.com> wrote:
> >>  1. Create non-blocking pipes which can be read in a separate thread
> >>  [...]
> >
> > You are correct on both of those points.
> 
>  I must be missing something.  What's wrong with spawning the subprocess
>  with subprocess.Popen as usual, passing subprocess.PIPE as stdin/stdout/
>  whatever, making your end nonblocking with fcntl.fcntl and then using
>  os.read/os.write in the obvious ways?

Nothing apart from the fact it doesn't work on windows.  The buffering
will cause you grief too.  If you want to do this properly under unix
use pexpect not subprocess.

  http://www.noah.org/wiki/Pexpect

Proper non blocking IO is an absolute nightmare under Windows in my
experience!  It really isn't the Windows way so you are fighting the
system the whole time.

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list