behavior of run_on_wait in Parallel::ForkManager

Discussion in 'Perl Misc' started by ctcgag@hotmail.com, Nov 2, 2004.

  1. Guest

    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->{on_wait}) eq 'CODE') {
    $s->{on_wait}->();
    if (defined $s->{on_wait_period}) {
    local $SIG{CHLD} = sub { } if ! defined $SIG{CHLD};
    select undef, undef, undef, $s->{on_wait_period}
    };
    };
    };

    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
    behavior?

    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->finish();
    };
    $pm->run_on_wait(sub {warn "Waiting Patiently to END. ", scalar time} ,
    $w); $pm->wait_all_children;



    Thanks,

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Nov 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nvp
    Replies:
    0
    Views:
    104
  2. nvp
    Replies:
    2
    Views:
    166
    Luc Heinrich
    Dec 31, 2009
  3. it_says_BALLS_on_your forehead

    Parallel::ForkManager and Net::FTP problem?

    it_says_BALLS_on_your forehead, Oct 7, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    433
    it_says_BALLS_on_your forehead
    Oct 10, 2005
  4. chaitu
    Replies:
    2
    Views:
    144
    chaitu
    Sep 21, 2006
  5. Jacob JKW
    Replies:
    1
    Views:
    144
    Jacob JKW
    Jan 24, 2008
Loading...

Share This Page