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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re^3: running a function for different list parallely using fork - Parallel::ForkManager by marioroy
in thread running a function for different list parallely using fork by noviceuser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found