Proc::Forkmap - map with forking
EXAMPLE:
use Proc::Forkmap qw(forkmap); $Proc::Forkmap::MAX_PROC = 4; sub foo { my $n = shift; sleep($n); print "slept for $n seconds\n"; } my @x = (1, 2, 3); forkmap { foo($_) } @x; # Or OO interface, if you like that sort of thing use Proc::Forkmap; sub foo { my $x = shift; my $t = sprintf("%1.0f", $x + 1); sleep $t; print "slept $t seconds\n"; } my @x = (rand(), rand(), rand()); my $p = Proc::Forkmap->new; $p->fmap(\&foo, @x);
This module provides mapping with built-in forking.
forkmap { foo($_) } @x;
These our variables control only the functional interface.
our
Max parallelism.
$Proc::Forkmap::MAX_PROC = 4;
Max time in seconds any single child process can run.
$Proc::Forkmap::TIMEOUT = 2;
my $p = Proc::Forkmap->new(max_kids => 4);
Maximum number of kids allowed in the pool. The default is 4.
Set IPC on/off state. IPC is off by default.
Defaults to 1, and falsy to block.
$p->max_kids(4);
max_kids setter/getter.
$p->fmap(\&foo, @x);
This method takes a coderef and an array. If IPC is blocking, then it will return a result set. Otherwise, it will continue, waiting for child processes to complete their tasks.
$p->ipc(1);
Turn on/off inter-process communication.
$p->non_blocking(1);
If IPC is on, then set IO::Handle blocking state. This might be useful for conditional parallelism.
Timeout in seconds.
$p->timeout(2);
Proc::Fork, IO::Pipe
Andrew Shapiro, <trski@cpan.org>
<trski@cpan.org>
Please report any bugs or feature requests to bug-proc-forkmap at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-Forkmap. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-proc-forkmap at rt.cpan.org
Copyright 2019 Andrew Shapiro.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information.
To install Proc::Forkmap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Proc::Forkmap
CPAN shell
perl -MCPAN -e shell install Proc::Forkmap
For more information on module installation, please visit the detailed CPAN module installation guide.