Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: running a function for different list parallely using fork - Parallel::ForkManager

by marioroy (Prior)
on Mar 16, 2023 at 02:32 UTC ( [id://11151005]=note: print w/replies, xml ) Need Help??


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

The "$pm->run_on_finish" method takes 2 additional arguments; signal_code and core_dump. I tried the following variation, based on ikegami's solution.

Parallel::ForkManager

use strict; use warnings; use Parallel::ForkManager qw( ); use Time::HiRes qw( time ); my @testLists = qw( sun moon wind air ); my $opts = 'foo'; my $status = 0; sub regressions { my ($opts, $list) = @_; print "$$: $list\n"; sleep 1; # simulate processing return 1; } my $start = time(); my $pm = Parallel::ForkManager->new( 2 ); # P::FM by default, only waits for its own child processes, # which is what we want. # Refer to 'BLOCKING CALLS' in the module documentation. # Let's decrease the sleep period time (default 1.0). $pm->set_waitpid_blocking_sleep(0.25); $pm->run_on_finish(sub { my ( $pid, $exit_code, $ident, $exit_signal, $core_dump, $data ) = +@_; if ( $exit_code || $exit_signal || $core_dump ) { # Handle error. } $status += $data->{ status }; }); for my $list ( @testLists ) { $pm->start and next; my $status = regressions( $opts, $list ); $pm->finish( 0, { status => $status } ); } $pm->wait_all_children(); print "status: $status\n"; printf "duration: %0.3f seconds\n", time() - $start; __END__ 27470: sun 27471: moon 27472: wind 27473: air status: 4 duration: 2.257 seconds

Replies are listed 'Best First'.
Re^4: running a function for different list parallely using fork - Parallel::ForkManager
by ikegami (Patriarch) on Mar 17, 2023 at 05:35 UTC

    Thanks, fixed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found