Parallel::SubArray - Execute forked subref array and join return values, timeouts and error captures.
use Parallel::SubArray 'par'; my $sub_arrayref = [ sub{ sleep(1); [1] }, # simple structure sub{ bless {}, 'a' }, # blessed structure sub{ while(1){$_++} }, # runaway routine sub{ die 'TEST' }, # bad code sub{ par()->([ # nested parallelism sub{ sleep(1); [1] }, sub{ sleep(2); {2,3} }, ]), }, ]; my($result_arrayref, $error_arrayref) = par(3)->($sub_arrayref); ## or you can ignore errors # my $result_arrayref = par(3)->($sub_arrayref); $result_arrayref == [ [ 1 ], {}, # blessed into 'a' undef, undef, [ [1], { 2 => 3 } ] ]; $error_arrayref == [ undef, undef, 'TIMEOUT', # can capture normal blessed exceptions aswell 'TEST at some file on some line', undef, ];
I want fast, safe, and simple parallelism. Current offerings did not satisfy me. Most are not enough while remaining are too complex or tedious. Palallel::SubArray scratches my itch: forking, joining, timeouts, return values, and error handling done simply.
Nothing automatically. I don't like magic.
Takes one argument that represents timeout in seconds and evaluates into a subref that will execute subarrayref in parallel returning resultarrayref in scalar context or resultarrayref and errorarrayref in list context.
Timeout can be undef or zero. In this case timeout is disabled and you might never join forks.
When nesting parallelism, keep in mind the outer timeout. Because if inner par is cut off by the timeout of the outer, you will not be able to recover return nor error values of finished inner processes as the whole inner par is considered to be a runaway process.
par
par can die if unable to fork.
perlipc "fork" in perlfunc perlfork subs::parallel Parallel::Simple Parallel::Queue Parallel::Forker Parallel::Jobs Parallel::Workers Parallel::SubFork Parallel::Pvm Parallel::Performing Parallel::Fork::BossWorker Parallel::ForkControl Proc::Fork
Expect lots if Windows and/or OOP is used. Windows because of the lack of forking and OOP because it requires locking. This module is designed functionally and is relying on copy-on-write forking.
The joining mechanism of this module can be incompatible with other forking modules because it's waiting for child processes to finish. Nesting of par works as expected.
Subroutines passed to par that return anything other than references to simple Perl structures may behave unexpectedly. Joining relies on Storable.
Eugene Grigoriev,
let a b c d e f g = concat [e,f,d,g,c,f,b] in a "com" "gmail" "grigoriev" "eugene" "." "@"
BSD
To install Parallel::SubArray, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parallel::SubArray
CPAN shell
perl -MCPAN -e shell install Parallel::SubArray
For more information on module installation, please visit the detailed CPAN module installation guide.