in reply to Replacing Parallel::ForkManger With Thread::Queue

Then don't wait for all the children to finish? Set a callback with run_on_finish, detect from the exit code whether the child got results, and if so kill off the remaining children.
  • Comment on Re: Replacing Parallel::ForkManger With Thread::Queue

Replies are listed 'Best First'.
Re^2: Replacing Parallel::ForkManger With Thread::Queue
by shanu_040 (Sexton) on May 26, 2009 at 08:05 UTC
    HI,
    Following is the code for run_on_finish. I am writing data onto disk(/tmp/ directory) retrieved by each child process. and deleting those file after reading them.
    $pm->run_on_finish(sub { my ($pid, $exit_code, $ident) = @_; eval { my $filename = '/tmp/' . $$ . escape($ident); my $result_set; if (-e $filename) { $result_set = $obj->retrieve($filename); unlink($filename); }else { # need a new $timeout_result object every loop my $timeout_result = new DBWIZ::Search::ResultSet; $timeout_result->status('timeout'); $timeout_result->hits(-5); $result_set = $timeout_result; } $return{$ident} = $result_set; }; if ($@) { print STDERR "Problem with search module: $@\n"; } # print STDERR "database $ident done = exit $exit_code \n"; });

    $obj is the Data::Serializer object with following options
    my $obj = Data::Serializer->new( serializer => 'Storable', portable => '1', encoding => 'b64', );
        Posted for your referenceYSTH, so that you get know what am I doing in run_on_finish. Could you please look at the first post for questions.