Sergeyk has asked for the wisdom of the Perl Monks concerning the following question:
use Parallel::ForkManager; my %retrieved_responses = (); $file_name='config'; if ( ! open CISCOFILE, $file_name ) { die "Couldnt open router config file! ($!)"; } @all_data=<CISCOFILE>; $MAX_PROCESSES=10; $TEMP_FOLDER='temporary_folder'; mkdir("$TEMP_FOLDER"); $pm = new Parallel::ForkManager($MAX_PROCESSES,"$TEMP_FOLDER"); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $dat +a_structure_reference) = @_; if (defined($data_structure_reference)) { my $string = ${$data_structure_reference}; print "Child send this result $string to parent\n"; $retrieved_responses{$ident} = $data_structure_reference; } else { print qq|No message received from child process $pid!\n|; } print "** $ident just got out of the pool ". "with PID $pid and exit code: $exit_code\n"; } ); $pm->run_on_start( sub { my ($pid,$ident)=@_; #diag print "** $ident started, pid: $pid\n"; } ); $pm->run_on_wait( sub { #diag print "** Have to wait for one children ...\n" }, 0.5 ); $i=0; foreach $data (@all_data) { chomp($data); $i=$i+1; my $pid = $pm->start($i) and next; squabble($data); } $pm->wait_all_children; rmdir("$TEMP_FOLDER"); @key_arr=keys(%retrieved_responses); foreach $string(@key_arr) { print "$string ${$retrieved_responses{$string}}\n"; } sub squabble { open(SUBINTFILE, ">>","child.txt") or die "Can't open file for wri +ting $!"; select SUBINTFILE; print "$$ $data\n"; close SUBINTFILE; $return_string=$data; sleep 1; $pm->finish(0,\$return_string); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::ForkManager child returns no data
by Mr. Muskrat (Canon) on May 08, 2012 at 18:42 UTC | |
|
Re: Parallel::ForkManager child returns no data
by derby (Abbot) on May 09, 2012 at 00:34 UTC | |
|
Re: Parallel::ForkManager child returns no data
by Sergeyk (Novice) on May 08, 2012 at 19:07 UTC | |
|
Re: Parallel::ForkManager child returns no data
by Sergeyk (Novice) on May 09, 2012 at 04:23 UTC |