in reply to Re^2: Parallel::Forkmanager question
in thread Parallel::Forkmanager question
As your output shows, the same process is handling all the tasks. That's because the parent is forking a child but then continuing the work itself.
You are missing the statement that causes the parent to skip out of the loop. See the doc for Parallel::ForkManager, which states (emphasis added):
The following example shows the difference:
Output:use strict; use warnings; use feature 'say'; use Parallel::ForkManager; use Time::HiRes qw/ time /; $|++; my $forker = Parallel::ForkManager->new(4); say "v.1"; for ( 0 .. 9 ) { my $pid = $forker->start; if ( $pid ) { say "1 $$ $_ start: " . time; sleep 1; } $forker->finish; } my $forker2 = Parallel::ForkManager->new(4); say "v.2"; for ( 0 .. 9 ) { my $pid = $forker->start and next; say "2 $$ $_ start: " . time; sleep 1; $forker->finish; } __END__
$ perl 1187274.pl v.1 1 19015 0 start: 1491486225.44169 1 19015 1 start: 1491486226.44244 1 19015 2 start: 1491486227.44318 1 19015 3 start: 1491486228.44402 1 19015 4 start: 1491486229.44495 1 19015 5 start: 1491486230.44586 1 19015 6 start: 1491486231.447 1 19015 7 start: 1491486232.44791 1 19015 8 start: 1491486233.44877 1 19015 9 start: 1491486234.4497 v.2 2 19026 0 start: 1491486235.45079 2 19027 1 start: 1491486235.45113 2 19028 2 start: 1491486235.45138 2 19029 3 start: 1491486235.4517 2 19030 4 start: 1491486237.45457 2 19031 5 start: 1491486237.45492 2 19032 6 start: 1491486237.45516 2 19033 7 start: 1491486237.45543 2 19035 9 start: 1491486239.45953 2 19034 8 start: 1491486239.45992
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parallel::Forkmanager question
by jamesgerard1964 (Novice) on Apr 06, 2017 at 21:28 UTC | |
|
Re^4: Parallel::Forkmanager question
by jamesgerard1964 (Novice) on Apr 06, 2017 at 21:43 UTC |