behavior of run_on_wait in Parallel::ForkManager

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Parallel::ForkManager allows one to set a code-ref to be run when the
parent program has to wait for children to exit (because the limit on
number of active children has been met or exceeded).  One can set a timer
to determine how often the callback is invoked during extended waiting.
However, I do not want it to wait unnecessarily, i.e. the waiting period
should apply only to another callback, and not to other events which could
allow the main program to proceed, like the exit of one of the children it
is waiting on.

The module code implementing this is:

sub on_wait { my ($s)=@_;
  if(ref($s->) eq 'CODE') {
    if (defined $s->) {
        local $SIG = sub { } if ! defined $SIG;
        select undef, undef, undef, $s->

What I am observing (on Linux, under both Perl 5.6.1 and 5.8.0) is that
sometimes the receipt of a SIGCHLD will interupt the "select", and then
allow the program to go on it's way without finishing the time (The desired
result); while sometimes the receipt of a SIGCHLD will apparently either
not interupt the "select" at all, or will interupt it but them restart it.
(not the desired result.)

As best as I can tell from experimentation, the desired behavior happens
only the first time the on_wait method is invoked, and the undesired
behavior happens thereafter, although I am far from certain about that.

Is there a simple change I can make so that I always get the desired

Experiments done with:

use strict;
use warnings;
use Parallel::ForkManager;

my $w=10;
my $s=5;

my $pm=Parallel::ForkManager->new(2);
$pm->run_on_wait(sub {warn "Waiting Patiently. ", scalar time} , $w);
foreach (1..5) {
  $pm->start() and next;
  warn "Started event $_. ", scalar time;
  sleep $s;
  warn "Ending event $_. ", scalar time;
$pm->run_on_wait(sub {warn "Waiting Patiently to END. ", scalar time} ,
$w); $pm->wait_all_children;



-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

Site Timeline