Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Parallel ForkManager error with run_on_wait()

by sojourn548 (Acolyte)
on Jun 01, 2013 at 04:06 UTC ( #1036376=perlquestion: print w/replies, xml ) Need Help??
sojourn548 has asked for the wisdom of the Perl Monks concerning the following question:

When using Parallel ForkManager 0.7.5 with run_on_wait(), I am seeing this error before the script terminates abnormally:

Use of uninitialized value in block exit at /lib/site_perl/5.8.7/Paral +lel/ line 365. Use of uninitialized value in block exit at /lib/site_perl/5.8.7/Paral +lel/ line 365. Unable to create sub named "" at /lib/site_perl/5.8.7/Parallel/ForkMan line 365. Good-Bye...

This is a constantly running process that seems to error out with the same message about once every 10 days or so, and it started occurring after I updated the script to use run_on_wait(). run_on_wait() is used to call a routine every second, and keeps track of forked processes and sends TERM signal to those child processes that have been running longer than 4 seconds. I am unsure how to go about debugging this, as this error seems to occur in rare occasions. I appreciate taking the time to review this, and thanks in advance.

our %procs; use constant LIMIT => 4 $pm->run_on_wait(\&term_process, 1); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; my ($check_id, $host) = $ident =~ /^(.*?) on (.*)/s; print("run_on_finish: $ident (pid: $pid) exited with code: [$e +xit_code] host: [$host]\n"); delete $procs{$pid}; print("proc_mgmt: $ident: deleting (pid: $pid) from list\n"); } ); $pm->run_on_start( sub { my ($pid,$ident)=@_; print("** $ident started, pid: $pid\n"); $procs{$pid} = time(); } ); sub term_process{ my $debug_time; my $total_time; while (my ($pid, $started_at) = each %procs) { next unless time() - $started_at > LIMIT; $debug_time = time(); $total_time = $debug_time - $started_at; print("[$pid] hung. time now: [$debug_time] - [$started_at] = [$t +otal_time] sending KILL."); kill TERM => $pid; delete $procs{$pid}; } }

Looking at

357 sub run_on_wait { my ($s,$code, $period)=@_; 358 $s->{on_wait}=$code; 359 $s->{on_wait_period} = $period; 360 } 361 362 sub on_wait { my ($s)=@_; 363 if(ref($s->{on_wait}) eq 'CODE') { 364 $s->{on_wait}->(); 365 if (defined $s->{on_wait_period}) { 366 local $SIG{CHLD} = sub { } if ! defined $SIG{CHLD}; 367 select undef, undef, undef, $s->{on_wait_period} 368 }; 369 }; 370 };

Replies are listed 'Best First'.
Re: Parallel ForkManager error with run_on_wait()
by frozenwithjoy (Priest) on Jun 01, 2013 at 05:17 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1036376]
Approved by sundialsvc4
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-03-18 17:36 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.