Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: running a function for different list parallely using fork

by ikegami (Patriarch)
on Mar 22, 2023 at 19:50 UTC ( [id://11151134]=note: print w/replies, xml ) Need Help??


in reply to Re^3: running a function for different list parallely using fork
in thread running a function for different list parallely using fork

P::FM forks a child for each "task". If you provide a limit (e.g. the 2), it waits for children to finish before forking if forking would bring the number of children over the limit.

use v5.14; use warnings; use Parallel::ForkManager qw( ); use Time::HiRes qw( sleep ); my $pm = Parallel::ForkManager->new ( 2 ); for ( 1 .. 9 ) { $pm->start and next; say "[$_] start"; sleep( $_ == 1 ? 4 : 0.3 ); say "[$_] done"; $pm->finish; } $pm->wait_all_children();

Annotated output:

1 2 3 4 5 6 7 8 9 ----- --- --- --- --- --- --- --- --- --- [1] start 1 XXX [2] start 1 & 2 XXX XXX [2] done 1 XXX [3] start 1 & 3 XXX XXX [3] done 1 XXX [4] start 1 & 4 XXX XXX [4] done 1 XXX [5] start 1 & 5 XXX XXX [5] done 1 XXX [1] done [6] start 6 XXX [7] start 6 & 7 XXX XXX [6] done 7 XXX [7] done [8] start 8 XXX [9] start 8 & 9 XXX XXX [8] done 9 XXX [9] done

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-19 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found