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); }

In reply to Parallel::ForkManager child returns no data by Sergeyk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.