forked from perl/perl-Parallel-ForkManager
107 lines
3.2 KiB
RPMSpec
107 lines
3.2 KiB
RPMSpec
|
|
#
|
||
|
|
# spec file for package perl-Parallel-ForkManager (Version 0.7.9)
|
||
|
|
#
|
||
|
|
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||
|
|
#
|
||
|
|
# All modifications and additions to the file contributed by third parties
|
||
|
|
# remain the property of their copyright owners, unless otherwise agreed
|
||
|
|
# upon. The license for this file, and modifications and additions to the
|
||
|
|
# file, is the same license as for the pristine package itself (unless the
|
||
|
|
# license for the pristine package is not an Open Source License, in which
|
||
|
|
# case the license is the MIT License). An "Open Source License" is a
|
||
|
|
# license that conforms to the Open Source Definition (Version 1.9)
|
||
|
|
# published by the Open Source Initiative.
|
||
|
|
|
||
|
|
# Please submit bugfixes or comments via http://bugs.opensuse.org/
|
||
|
|
#
|
||
|
|
|
||
|
|
Name: perl-Parallel-ForkManager
|
||
|
|
Version: 0.7.9
|
||
|
|
Release: 1
|
||
|
|
License: GPL+ or Artistic
|
||
|
|
%define cpan_name Parallel-ForkManager
|
||
|
|
Summary: A simple parallel processing fork manager
|
||
|
|
Url: http://search.cpan.org/dist/Parallel-ForkManager/
|
||
|
|
Group: Development/Libraries/Perl
|
||
|
|
Source: http://www.cpan.org/authors/id/D/DL/DLUX/%{cpan_name}-%{version}.tar.gz
|
||
|
|
BuildArch: noarch
|
||
|
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||
|
|
BuildRequires: perl
|
||
|
|
BuildRequires: perl-macros
|
||
|
|
BuildRequires: perl(ExtUtils::MakeMaker)
|
||
|
|
%{perl_requires}
|
||
|
|
|
||
|
|
%description
|
||
|
|
This module is intended for use in operations that can be done in parallel
|
||
|
|
where the number of processes to be forked off should be limited. Typical
|
||
|
|
use is a downloader which will be retrieving hundreds/thousands of files.
|
||
|
|
|
||
|
|
The code for a downloader would look something like this:
|
||
|
|
|
||
|
|
use LWP::Simple;
|
||
|
|
use Parallel::ForkManager;
|
||
|
|
|
||
|
|
...
|
||
|
|
|
||
|
|
@links=(
|
||
|
|
["http://www.foo.bar/rulez.data","rulez_data.txt"],
|
||
|
|
["http://new.host/more_data.doc","more_data.doc"],
|
||
|
|
...
|
||
|
|
);
|
||
|
|
|
||
|
|
...
|
||
|
|
|
||
|
|
# Max 30 processes for parallel download
|
||
|
|
my $pm = new Parallel::ForkManager(30);
|
||
|
|
|
||
|
|
foreach my $linkarray (@links) {
|
||
|
|
$pm->start and next; # do the fork
|
||
|
|
|
||
|
|
my ($link,$fn) = @$linkarray;
|
||
|
|
warn "Cannot get $fn from $link"
|
||
|
|
if getstore($link,$fn) != RC_OK;
|
||
|
|
|
||
|
|
$pm->finish; # do the exit in the child process
|
||
|
|
}
|
||
|
|
$pm->wait_all_children;
|
||
|
|
|
||
|
|
First you need to instantiate the ForkManager with the "new" constructor.
|
||
|
|
You must specify the maximum number of processes to be created. If you
|
||
|
|
specify 0, then NO fork will be done; this is good for debugging purposes.
|
||
|
|
|
||
|
|
Next, use $pm->start to do the fork. $pm returns 0 for the child process,
|
||
|
|
and child pid for the parent process (see also the perlfunc(1p)/fork()
|
||
|
|
manpage). The "and next" skips the internal loop in the parent process.
|
||
|
|
NOTE: $pm->start dies if the fork fails.
|
||
|
|
|
||
|
|
$pm->finish terminates the child process (assuming a fork was done in the
|
||
|
|
"start").
|
||
|
|
|
||
|
|
NOTE: You cannot use $pm->start if you are already in the child process. If
|
||
|
|
you want to manage another set of subprocesses in the child process, you
|
||
|
|
must instantiate another Parallel::ForkManager object!
|
||
|
|
|
||
|
|
%prep
|
||
|
|
%setup -q -n %{cpan_name}-%{version}
|
||
|
|
|
||
|
|
%build
|
||
|
|
%{__perl} Makefile.PL INSTALLDIRS=vendor
|
||
|
|
%{__make} %{?_smp_mflags}
|
||
|
|
|
||
|
|
%check
|
||
|
|
%{__make} test
|
||
|
|
|
||
|
|
%install
|
||
|
|
%perl_make_install
|
||
|
|
%perl_process_packlist
|
||
|
|
%perl_gen_filelist
|
||
|
|
|
||
|
|
%clean
|
||
|
|
%{__rm} -rf %{buildroot}
|
||
|
|
|
||
|
|
%files -f %{name}.files
|
||
|
|
%defattr(-,root,root,755)
|
||
|
|
%doc Changes examples TODO
|
||
|
|
|
||
|
|
%changelog
|