[Python-ideas] Tulip / PEP 3156 - subprocess events

Guido van Rossum guido at python.org
Sat Jan 19 00:01:54 CET 2013


On Fri, Jan 18, 2013 at 2:57 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 18 January 2013 22:15, Guido van Rossum <guido at python.org> wrote:
>> But for this specific case there's a simpler solution -- require the
>> protocol to support a few extra methods, in particular,
>> err_data_received() and err_eof_received(), which are to stderr what
>> data_received() and eof_received() are for stdout. (After all, the
>> point of a subprocess is that "normal" data goes to stdout.) There's
>> only one input stream to the subprocess, so there's no ambiguity for
>> write(), and neither is there a need for multiple
>> connection_made()/lost() methods. (However, we could argue endlessly
>> over whether connection_lost() should be called when the subprocess
>> exits, or when the other side of all three pipes is closed. :-)
>
> While I don't really care about arguing over *when* connection_lost
> should be called, it *is* relevant to my thinking that getting
> notified when the process exits doesn't seem to me to be possible -
> again it's the issue that the transport can't ask the event loop to
> poll for anything that the event loop isn't already coded to check. So
> (once again, unless I've missed something) the only viable option for
> a standalone transport is to call connection_lost when all the pipes
> are closed.

That is typically how these things are done (e.g. popen and subprocess
work this way). It is also probably the most useful, since it is
*possible* that the parent process forks a child and then exits
itself, where the child does all the work of the pipeline.

> Am I still missing something?

I believe it is, at least in theory, possible to implement waiting for
the process to exit, using signals. The event loop can add signal
handlers, and there is a signal that gets sent upon child process
exit. There are lots of problems here (what if some other piece of
code forked that process) but we could come up with reasonable
solutions for these.

However waiting for the pipes closing makes the most sense, so no need
to bother. :-)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list