Sergeyk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all! I use Parallel::ForkManager for the distribution of work between the processes. And now I have only one problem. My code works correctly in Windows Active Perl. But in Linux $pm->finish(0,\$return_string); does not return a data structure to the parent process. Anyone else encountered a similar problem using this module?
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

    Add use strict; to the file right before use Parallel::ForkManager;. Then fix all of the compilation errors you get when you test the file with perl -c. Once you've done that it should be easy to figure out why it didn't work correctly in the state you presented it to us.

Re: Parallel::ForkManager child returns no data
by derby (Abbot) on May 09, 2012 at 00:34 UTC

    What version of Parallel::ForkManager is on the nix box? That serialized return feature is only since version 0.7.6

    -derby
Re: Parallel::ForkManager child returns no data
by Sergeyk (Novice) on May 08, 2012 at 19:07 UTC
    After perl -с. I've added "my" to some variables. After that "perl -с myfile" produces "syntax OK" But the result is the same, child does not pass data back to parent
Re: Parallel::ForkManager child returns no data
by Sergeyk (Novice) on May 09, 2012 at 04:23 UTC
    old module led to this problem it is installed automatically by command perl-MCPAN-e 'install Parallel :: ForkManager' I installed it manually