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; }
|
---|