in reply to Graceful shutdowns and Parallel::ForkManager
Here's the implementation of P::FM::start (found by doing vi `perldoc -l Parallel::ForkManager`):
If you look at the "} else {" branch, you'll see that if no processes are available (when $s->{max_proc}==0, what set_max_procs(0) does), the task is continued in the parent process.sub start { my ($s,$identification)=@_; die "Cannot start another process while you are in the child process +" if $s->{in_child}; while ( ( keys %{ $s->{processes} } ) >= $s->{max_proc}) { $s->on_wait; $s->wait_one_child(defined $s->{on_wait_period} ? &WNOHANG : undef +); }; $s->wait_children; if ($s->{max_proc}) { my $pid=fork(); die "Cannot fork: $!" if !defined $pid; if ($pid) { $s->{processes}->{$pid}=$identification; $s->on_start($pid,$identification); } else { $s->{in_child}=1 if !$pid; } return $pid; } else { $s->{processes}->{$$}=$identification; $s->on_start($$,$identification); return 0; # Simulating the child which returns 0 } }
That looks like a cool feature, actually, since you can test out your code in a single process loop before going parallel, if you like.
I think you should have your alarm sig set a flag, which you could check in your "my $data" loop:
Hmmm, I think that'd work... Not sure, though.my $stopFlag=0; $SIG{ARLM} = sub { $stopFlag=1; }; alarm($MAX_TIME); foreach my $data (@all_data) { last if $stopFlag; my $pid = $pm->start and next; # Process or call processing routines # for $data here $pm->finish; } $pm->wait_all_children; alarm(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Graceful shutdowns and Parallel::ForkManager
by atcroft (Abbot) on Jul 25, 2002 at 20:03 UTC | |
by particle (Vicar) on Jul 25, 2002 at 22:59 UTC | |
by atcroft (Abbot) on Jul 26, 2002 at 04:48 UTC | |
by ChemBoy (Priest) on Jul 26, 2002 at 05:27 UTC | |
by atcroft (Abbot) on Jul 26, 2002 at 05:39 UTC | |
by RMGir (Prior) on Jul 25, 2002 at 20:26 UTC | |
by atcroft (Abbot) on Jul 25, 2002 at 20:55 UTC | |
by RMGir (Prior) on Jul 25, 2002 at 21:08 UTC | |
by atcroft (Abbot) on Jul 26, 2002 at 04:43 UTC | |
|