Re: USE_SIGCHLD

Rocco Caputo <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
In other words, it eliminates that up-to-1-second wait for child  
processes that always annoyed you.  Without resorting to a faster,  
less efficient polling interval. :)

Yuval: Reviewing the code, it looks like the SIGCHLD handler may be  
triggered multiple times before the EN_SCPOLL event could be  
dispatched.  That would enqueue redundant EN_SCPOLL events, and it  
could be marginally unoptimal.

Would it be feasible to disable the SIG$_[0] handler from the handler  
and then re-enable it just before the children are reaped?  Something  
like this:

# In POE::Loop::PerlSignals:
sub _loop_signal_handler_chld {
   if (TRACE_SIGNALS) {
     POE::Kernel::_warn "<sg> Enqueuing CHLD-like SIG$_[0] event";
   }

   $poe_kernel->_data_sig_enqueue_poll_event();
   $SIG{$_[0]} = sub { }; # temporarily ignore
}

# In POE::Resource::Signals:
sub _data_sig_handle_poll_event {
   my $self = shift;

   if ( USE_SIGCHLD ) {
     # Turn on the handler just before polling.  Leaves a window
     # open for redundancy, but avoids a gap where races could
     # lose children.
     $SIG{CHLD} = $SIG{CLD} = \&_loop_signal_handler_chld;
     $polling_for_signals = undef;
   }

   ... gather child process state ...;
}

-- 
Rocco Caputo - [email protected]


On Jun 6, 2008, at 06:33, Yuval Kogman wrote:

> Hello POE hackers
>
> POE 1.0001 had a patch that conditionally enabled $SIG{CHLD} support
> for immediate reaping of child processes (as opposed to POE's once
> per second polling).
>
> Instead of polling at an interval, the same polling code is
> immediatley queued after SIGCHLD arrives, so that on the next loop
> cycle wait() is called, and SIGCHLD is delivered. This means that
> system() etc are still supposed to continue working inside POE code,
> because the SIGCHLD handler never calls wait() itself, and thus
> doesn't interfere with Perl's wait() call.
>
> Anyway, this code tries to be compatible, but is probably subtly
> different, so please run
>
> 	env POE_USE_SIGCHLD=1 make test
>
> on your code and tell me if it breaks before I forget what I did.
>
> kthx, xoxo
> nothingmuch
>
> -- 
>  Yuval Kogman <[email protected]>
> http://nothingmuch.woobling.org  0xEBD27418
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.