Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by tybalt89 (Monsignor)
on Mar 17, 2023 at 01:25 UTC ( [id://11151016]=note: print w/replies, xml ) Need Help??


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

And here's the Forking::Amazing version. See Re: figuring out Parallel::ForkManager slots for the Forking::Amazing module, which I wrote because I didn't particularly care for Parallel::ForkManager. I think Forking::Amazing makes it clearer what runs in the child and what runs in the parent, and makes it easier to pass results from the child back to the parent.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11150996 use warnings; use Forking::Amazing; my @testLists = 1 .. 10; # FAKE for testing my $opts = 'opts'; # FAKE for testing my $status = 0; Forking::Amazing::run 2, # max forks sub { return [ regressions($opts, @_) ]; }, # child sub { $status += $_[1][0]; }, # parent @testLists; # argument for each fork print "status $status\n"; sub regressions # FIXME for testing { print time, " pid $$ starting on (@_)\n"; select undef, undef, undef, 1 + rand 3; print time, " pid $$ ending on (@_)\n"; return pop; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found