popen5: New POSIX process module

Peter Astrand astrand@lysator.liu.se
Fri, 31 Oct 2003 12:43:58 +0100

I've written a new popen-like module for Python. This module overcomes =

several limitations with the old popen2 module, but also aims to be a =

generic module for starting and communicating with processes on POSIX =

systems. It can replace several older modules and functions, like:


This module features:

* Cross-process exceptions: Exceptions happening in the child before the =

new process has started to execute are re-raised in the parent. This =

means that it's easy to handle exec() failures, for example. With =

popen2, it's impossible to detect if the execution failed.

* A hook for executing customized code between fork and exec. This can =

be used for, for example, changing uid.

* No implicit call of /bin/sh. This means that there is no need for =

escaping dangerous shell meta characters.

* A communicate() method, which makes it easy to send stdin data and =

read stdout and stderr data, without risking deadlocks.

* Support for connecting several subprocesses (shell "pipe").

The module is available from
pen5, =

or via anonymous CVS =


All feedback is appreciated.

/Peter =C5strand <astrand@lysator.liu.se>