IPC::QWorker - Perl extension for processing a queue in parallel
my $qworker = IPC::QWorker->new(); $qworker->create_workers(10, 'dump' => sub { my $ctx = shift(); print $$.": ".Dumper(@_)."\n"; $ctx->{'count'}++; }, '_init' => sub { my $ctx = shift(); $ctx->{'count'} = 0 ; }, '_destroy' => sub { my $ctx = shift(); print $$.": did ".$ctx->{'count'}." operations!\n"; } ); foreach $i (1..120) { $qworker->push_queue(IPC::QWorker::WorkUnit->new( 'cmd' => 'dump', 'params' => $i, )); } $qworker->process_queue(); # wait till queue is emtpy $qworker->flush_queue(); # then stop all workers $qworker->stop_workers();
This Module creates a group of child processes and feeds them with data from a queue.
With this module you can fork a few child processes which know a few function calls you define while creating them. Later you can pass command with parameters into the queue which is distributed across the child processes thru pipes(with the Storable module).
None by default.
perl, POSIX, Storable, IO::Select
Markus Benning, <me@w3r3wolf.de>
Copyright 2013 by Markus Benning <me@w3r3wolf.de>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install IPC::QWorker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::QWorker
CPAN shell
perl -MCPAN -e shell install IPC::QWorker
For more information on module installation, please visit the detailed CPAN module installation guide.