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 };

In reply to Parallel ForkManager error with run_on_wait() by sojourn548

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.