Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Many children, but never more than a fixed number at once.

by gav^ (Curate)
on Jun 20, 2002 at 03:05 UTC ( #175894=note: print w/ replies, xml ) Need Help??


in reply to Many children, but never more than a fixed number at once.

I find Parallel::ForkManager good for this kind of thing as it lets you write:

use Parallel::ForkManager; $pm = new Parallel::ForkManager($MAX_PROCESSES); foreach $data (@all_data) { # Forks and returns the pid for the child: my $pid = $pm->start and next; ... do some work with $data in the child process ... $pm->finish; # Terminates the child process }
Code stolen from docs :)

gav^


Comment on Re: Many children, but never more than a fixed number at once.
Download Code
Re: Many children, but never more than a fixed number at once.
by Abigail-II (Bishop) on Jul 08, 2002 at 16:33 UTC
    Yeah, but that requires you to do three lines of code - to create an object (why? What's so OO about this?), and two calls (to ->start and ->finish) for each piece of code you want to execute.

    With mfork or afork, all you have is one call.

    But this is Perl, so there are more ways to do things.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://175894]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-12-25 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls