[Tutor] script hangs when attempting to read Popen3 output

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Nov 10 22:15:04 CET 2004



On Tue, 9 Nov 2004, Kent Johnson wrote:

> I think there are deadlock issues with popen.


Yes, we have to be sorta careful when doing popen-ish stuff.  Take a look
at:

    http://www.python.org/doc/lib/popen2-flow-control.html

which explains some of the difficulties.



> > the script hangs when I try to read the command output. It seems I can
> > provide multi-line input, but I cant read any lines from the output of a
> > command that is still recieving input. I have to close the input before
> > reading any output. That doesnt seem very "pipe-ish" to me. Am I doing
> > something wrong, or just expecting the wrong behavior?


Expecting wrong behavior.  *grin*

You may need to close the input stream.  Some Unix commands, like 'cat',
might not start sending stuff out until either their buffers fill up, or
until the input stream closes down.


It's very funny how reinvention works: I had just finished writing a thin
process-executing wrapper yesterday!  *grin* It simulates the 'tee'
utility, except that it also captures standard error.


If you're interested, here's a link to it:

http://aztec.stanford.edu/svn/repos/personal/dyoo/scratch/2004/python/wrap_shell_command.py




Good luck to you!



More information about the Tutor mailing list