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

Hi,
My script searches different databases and all the databases have their own searching and screen-scraping module. Each search module run parallel to each other using Parallel::ForkManager.
But My problem is that the Parallel::ForkManager waits for all children to be finished then only it display the results.
What I want it should return the results as soon as it gets the results from a database. I mean one child get finished its task.
sub parallel_search{ foreach my $key (keys %$searches) { my $pid = $pm->start($key) and next; $result_set = new Search::ResultSet; $parsed_search = $$searches{$key}->parse_search(); $result_set = $$searches{$key}->get_search_results($parsed_search, $ke +y); $pm->finish; } $pm->wait_all_children; return($result_set); }

Replies are listed 'Best First'.
Re: Parallel Processing in Perl
by CountZero (Bishop) on Oct 20, 2008 at 05:46 UTC
    It seems you never got farther than the SYNOPSIS of that module or you would have discovered the run_on_finish $code [, $pid ] method which does what you want.

    PS: This was already suggested to you in Re: Running a Perl Code in different Processes

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    A reply falls below the community's threshold of quality. You may see it by logging in.