Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by gav^ (Curate)
on Jun 20, 2002 at 03:05 UTC ( [id://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^

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://175894]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-18 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found