os.pipe and subprocess under Windows

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Mon Nov 17 07:43:31 EST 2008


Jeremy Sanders wrote:

> Hi - I have some code which works under linux. It starts a remote python
> process using subprocess and communicates to it via a pipe created by
> os.pipe. As far as I understand, child processes should inherit file
> descriptors from the parent if close_fds=False on the suprocess.Popen
> command line.

Hmm... examining the code for os.pipe in posixmodule.c, it looks like pipes
are create specifically to be non-inheritable in Windows. I can't see why
you would want a non-inheritable pipe, so I would call this a bug. 

I suppose I could try this trick from subprocess.py to make the pipes
inheritable:

        def _make_inheritable(self, handle):
            """Return a duplicate of handle, which is inheritable"""
            return DuplicateHandle(GetCurrentProcess(), handle,
                                   GetCurrentProcess(), 0, 1,
                                   DUPLICATE_SAME_ACCESS)

Pretty nasty to have to do this though, and I would have to add a win32api
dependency, or hack around with the _subprocess module.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list