subprocess.Popen inheriting

Aaron Brady castironpi at gmail.com
Tue Dec 16 21:17:09 CET 2008


On Dec 16, 4:15 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Tue, 16 Dec 2008 07:29:19 -0200, Aaron Brady <castiro... at gmail.com>  
> escribió:
>
> > I have a file handle I want to inherit in a child process.  I am
> > looking at '_make_inheritable' in 'Popen', but it needs an instance,
> > and by the time I have one, the subprocess is already running.
>
> > Can't I call 'Popen._make_inheritable( None, handle )'?  The method
> > does not use 'self'.
>
> File handles are inherited by default, I think. What's your specific  
> problem?
>
> --
> Gabriel Genellina

I want a dual-console application for some multi-threaded output.  The
main process spawns a second process in a second window, and directs
its readout through a pipe.  That is, the second process is just a
dummy, print pipe directly to console.

It worked when I used the 'stdin= PIPE' keyword in Popen, but passing
my own pipe handle on the command line isn't working.  The keyword is
a workaround.

> File handles are inherited by default, I think.

I thought so too.  The web seems to say that on Linux they are, and on
Windows, you need to call DuplicateHandle for it.

By the way, there are a few solutions to the inheritance problem.

1.  Override __init__ and __del__ in a subclass.
2.  Assign DummyClass= Popen._make_inheritable
3.  Override Popen._execute_child to call _make_inheritable, then call
the super method.



More information about the Python-list mailing list