On Wed, Jun 26, 2002 at 12:24:55PM -0400, Peter Chen wrote:
> On Wed, 2002-06-26 at 11:08, Rocco Caputo wrote:
> > The paradigm has recently shifted regarding POE::Wheel::Run.  Its new
> > CloseEvent should now be a reliable and convenient way to tell when a
> > child has gone away.
> 
> So far I have been conservative by checking both CloseEvent and the
> arrival of SIGCHLD (mainly for the exit status).  
> 
> I have two concerns:
> 
> 1. Event sequence.
> 
> It's not clear to me whether it's possible for SIGCHLD to arrive after
> CloseEvent.

I'm sure there are times when SIGCHLD comes after CloseEvent.  Perl's
signal handlers are known to cause segfaults, so POE avoids using
them.  Instead it polls for children using waitpid(-1,WNOHANG) and
generates the CHLD signal events on its own.  It seems likely that a
child process may close its STDOUT and STDERR handles before waitpid()
detects it has gone away.

> 2. Exit status.
> 
> In many cases, CloseEvent alone is insufficient.  It only tells one that
> the child process has no more output, but one does not know whether the
> child has exited abnormally.  For example, it's possible that the child
> process was killed, in which case, one would need to know that the
> output might be incomplete.
>
> I separate theses exits into five categories: success, failure, error,
> timeout, and abort.
> 
> success - exit code 0, no signal, no coredump.
> failure - non-zero exit code, may have a signal, or a coredump.
> error   - the child process never started, check ErrorEvent.
> timeout - child killed by the system, because it timed out.
> abort   - child killed by the system based on a user request.
> 
> To make my life easier, since one of my application makes use of
> POE::Wheel::Run extensively, I wrote a module to encapsulate these
> states.

This is an excellent point.  If you've come up with a better interface
for child processes, we can do some harsh revising.  I'd really like
to see Wheel::Run redone as a component anyway.  Then it can manage
its own signal handlers.

> At one point I was also concerned whether there would be a problem
> deleting a wheel before its child process is reaped by waitpid.  Based
> on a quick look in POE::Kernel::_invoke_state, it looks as if the child
> process will be reaped regardless of whether the wheel still exists.

Yes, POE::Kernel will reap every CHLD/CLD signal it receives.  If you
want to make doubly sure the child dies, you can $wheel->kill(-9) it
before deleting the wheel.

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net

Reply via email to