swares has asked for the wisdom of the Perl Monks concerning the following question:

Trying to get a sig child handler routine working. I'm using POE::Wheel::Run and used the sample close handler from the POE docs but it dies on me and kills off the job server. It appears to be working at first then it dies.
[task_result] Child process in wheel 8 wrote to STDOUT: HASH(0x9b22c94 +) [task_result] Result for cmd: 32240\Kb (1.5%). [irc_bot_msg] I said '[task_result] Result for cmd: 32240\Kb (1.5%).' +to swares [task_close] Child 30750 has finished. [on_child] We have lost our children! (POE::Session=ARRAY(0x8fcf1a0)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9adc6d0)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9ad16c4)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9b231f8)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9b23a50)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9ad8d1c)) [on_child] We have lost our children! (POE::Session=ARRAY(0x9adb2e8)) [bot_stop] Stopping. Can't call method "PID" on an undefined value at ./cookbot.pl line 169 +4.
# The signal handler -
# handler for child processes (forking job server) $kernel->sig( CHLD => "task_close" );
Where I call the code -
my $task = POE::Wheel::Run->new( Program => sub { &{$this_code} }, ProgramArgs => \@program_args, StdoutFilter => POE::Filter::Reference->new(), StdinEvent => 'task_stdin', # Flushed all data to the child's +STDIN. StdoutEvent => 'task_result', # Received data from the child's +STDOUT. StderrEvent => 'task_debug', # Received data from the child's S +TDERR. # ErrorEvent => 'task_error', # An I/O error occurred. CloseEvent => 'task_close', # Child closed all output handle +s. ); $heap->{task}->{ $task->ID } = $task;
Here's the task_close event handler -
# Child close event sub task_close { my ($heap, $wheel_id) = @_[HEAP, ARG0]; my $result = $_[ARG0]; my $child = $heap->{task}->{$wheel_id}; print "[task_close] Child ", $child->PID, " has finished.\n"; $child = delete $heap->{task}->{$wheel_id}; }

Replies are listed 'Best First'.
Re: POE::Wheel::Run task_close handler problems.
by bingos (Vicar) on Apr 19, 2007 at 05:50 UTC

    You appear to be using the same state handler for POE::Wheel::Run's CloseEvent and for the SIGCHLD. They have different values in their ARG0 .. $#_ as well. You should definitely have separate state handlers for these.

    I tend to use sig_child() for handling CHLD instead of sig() as it gives you more flexibility in how one handles different types of child within the same session. It also implicitly keeps a session alive until the given child has been reaped, which sig() doesn't.