Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^4: Parallel::ForkManager and wait_all_children

by rgren925 (Beadle)
on May 13, 2015 at 22:13 UTC ( #1126612=note: print w/replies, xml ) Need Help??

in reply to Re^3: Parallel::ForkManager and wait_all_children
in thread Parallel::ForkManager and wait_all_children

Thanks all for the replies.

I've tried to synthesize the different approaches.

To flesh this out a bit, I'm planning on using callbacks (run_on_wait) to manage notifying/killing a hung process. Using the alarm(TIMEOUT) doesn't really solve my problem. If I set the timeout to 60, no other processes will run until that 60 seconds has elapsed as the wait_all_children still isn't satisfied.

wait_for_available_procs (which was newer than my version of Parallel::ForkManager--so I upgraded) didn't seem to make any difference.

The callbacks indicate that everything stalls until the looping script is killed.

use strict; use warnings; use Parallel::ForkManager; use constant TIMEOUT => 60; my @runArray = ("", "", "", "", "test5"); my ($pid, $exitCode, $ident); my $forkMgr = Parallel::ForkManager->new(3); $forkMgr->run_on_start( sub { ($pid, $ident) = @_; print "Started ==> $ident\n"; } ); $forkMgr->run_on_finish( sub { ($pid, $exitCode, $ident) = @_; print "Ended ==> $ident\n"; } ); while (1) { for my $runCommand (@runArray) { $forkMgr->start($runCommand) and next; alarm(TIMEOUT); system("/usr/localcw/opt/patrol/nagios/libexec/$runCommand") o +r die ("exec: $!\n"); } $forkMgr->wait_all_children; sleep 10; } exit;

Replies are listed 'Best First'.
Re^5: Parallel::ForkManager and wait_all_children
by ikegami (Patriarch) on May 14, 2015 at 14:31 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1126612]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2023-10-01 04:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found