Direct interaction with subprocess - the curse of blocking I/O

Nobody nobody at nowhere.com
Mon Jun 29 16:45:06 EDT 2009


On Mon, 29 Jun 2009 21:15:52 +0200, Pascal Chambon wrote:

> I've had real issues with subprocesses recently : from a python script, 
> on windows, I wanted to "give control" to a command line utility, i.e 
> forward user in put to it and display its output on console.

Are you talking about a popen(..., 'w') situation? I.e. where Python
feeds data to the child's stdin but the child's stdout doesn't go through
Python?

Or a slave process, where both stdin and stdout/stderr are piped to/from
Python?

The latter is inherently tricky (which is why C's popen() lets you connect
to stdin or stdout but not both). You have to use either multiple threads,
select/poll, or non-blocking I/O.

If the child's output is to the console, it should presumably be the
former, i.e. piping stdin but allowing the child to inherit stdout, in
which case, where's the problem? Or are you piping its stdout via Python
for the hell of it?




More information about the Python-list mailing list