I know you're using P::FM. However, I have to wonder if this would be easier to do with AnyEvent. I'm not entirely sure, as after about 10 minutes, I still don't have example code quite working :-) but maybe it's something to start with.
There is some tweaking required - this will start the first two groups of five, and wait - once the first five come in, it goes and starts the rest. It's not waiting properly. There is also AnyEvent::Util::fork_call which is quite similar to what you want to do, and you may be able to adapt its methods to what you want to do while still leaving much of the heavy lifting to AnyEvent.use 5.14.0; use EV; use AnyEvent; use AnyEvent::Util qw(run_cmd); use File::Spec; # set up my condvars my $all_done = AE::cv; $all_done->begin for 1..50; my $ten = AE::cv; # start the first 10... start_ten($ten, $all_done, $_) for 1..2; # wait for all of them to finish. $all_done->recv(); sub start_ten { my $t = shift; my $all = shift; my $one = shift; state $started = 0; # 10/100 too much for my machine... for (1..5) { $started ++; my $proc = $started; $t->begin if $one == 1; $all->end; print "Starting...$proc\n"; my $cv = run_cmd( ['sleep', rand(3)], '>' => File::Spec->devnull(), '2>' => File::Spec->devnull(), '<' => File::Spec->devnull(), ); $cv->cb( sub { my $c = shift; my $rc = $c->recv(); print "Finished $proc: $rc\n"; $t->end() }); } # when we're done, start the next ten. $t->cb( sub { my $c = shift; print "Checking next group...($started)\n"; $c->recv; $all->ready() or start_ten($t, $all, 1) }); }
Note that 100 processes being kicked off can do serious damage to your system's responsiveness. Hopefully you have the requisite CPU/RAM :-)
In reply to Re: Parallel::ForkManager How to wait when 1st 10 Child processe are over out of 100
by Tanktalus
in thread Parallel::ForkManager How to wait when 1st 10 Child processe are over out of 100
by anshumangoyal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |