When using Parallel ForkManager 0.7.5 (and the latest version 1.03) 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/ForkManager.pm line 365.
Use of uninitialized value in block exit at /lib/site_perl/5.8.7/Paral
+lel/ForkManager.pm line 365.
Unable to create sub named "" at /lib/site_perl/5.8.7/Parallel/ForkMan
+ager.pm 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 ForkManager.pm:
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 };
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.