NAME
Parallel::SubArray - Execute forked subref array and join return values, timeouts and error captures.
SYNOPSIS
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,
];
DESCRIPTION
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.
EXPORTS
Nothing automatically. I don't like magic.
par
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
can die if unable to fork.
SEE ALSO
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
BUGS
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.
AUTHOR
Eugene Grigoriev,
let a b c d e f g = concat [e,f,d,g,c,f,b] in
a "com" "gmail" "grigoriev" "eugene" "." "@"
LICENSE
BSD