Proc-tored-Pool 0.07

managed work pool with Proc::tored and Parallel::ForkManager


Platform: CPAN

Language: Perl

License: Artistic-1.0-Perl

View on registry:


Proc::tored::Pool - managed work pool with Proc::tored and Parallel::ForkManager


version 0.07


  use Proc::tored::Pool;

  # Create a worker pool service
  my $pool = pool 'thing-doer', in '/var/run', capacity 10,
    on success, call {
      my ($me, $id, @results) = @_;
      print "thing $id complete: @results";
    on failure, call {
      my ($me, $id, $message) = @_;
      warn "thing $id failed: $message";

  # Do things with the pool
  run {
    my ($thing_id, $thing) = get_next_thing();
    process { do_things($thing) } $pool, $thing_id;
  } $pool;

  # Control the pool as a Proc::tored service
  pause $pool;
  resume $pool;
  stop $pool;
  zap $pool, 15 or die "timed out after 15 seconds waiting for pool to stop";
  start $pool;


Provides a simple and fast interfact to build and manage a pool of forked worker processes. The process is controlled using a pidfile and touch file.


As a Proc::tored::Pool is a Proc::tored service, it by default exports the same functions as "EXPORTED SUBROUTINES" in Proc::tored.

In addition, the following subroutines are exported by default.


Creates the pool (an instance of Proc::tored::Pool::Manager). Requires a $name as its first argument.

  my $pool = pool 'the-proletariat', ...;


Sets the max number of forked worker processes to be permitted at any given time.

  my $pool = pool 'the-proletariat', capacity 16, ...;


Builds an event callback with one of "assignment", "success", or "failure".

  my $pool = pool 'the-proletariat', capacity 16,
    on success, call { ... };


Defines the code to be called by an event callback. See "on".


Returns the number of tasks that have been assigned to worker processes but have not yet completed.


Sends a task (a CODE ref) to the pool, optionally specifying a task id to identify the results in callbacks. The return value of the supplied code ref is passed as is to the "success" callback (if supplied).

  process { seize_the_means_of_production() } $pool;
  process { seize_the_means_of_production() } $pool, $task_id;


For situations in which a task or tasks must be completed before program execution can continue, sync may be used to block until all pending tasks have completed. After calling sync, there will be no pending tasks and all callbacks for previously submitted tasks will have been called.

  process { seize_the_means_of_production() } $pool;
  sync $pool;



Triggered immediately after a task is assigned to a worker process. Receives the pool object and the task id (if provided when calling "pool").

  my $pool = pool 'thing-doer', ...,
    on assignment, call {
      my ($self, $task_id) = @_;
      $assigned{$task_id} = 1;

  process { do_things() } $pool, $task_id;


Triggered after the completion of a task. Receives the pool object, task id (if provided when calling "pool"), and the return value of the code block.

  my $pool = pool 'thing-doer', ...,
    on success, call {
      my ($self, $task_id, @results) = @_;

  process { do_things() } $pool, $task_id;

If "process" performs an exec, no data is returned from the worker process (because exec never returns). In this case, if the process had a zero exit status, the success callback is triggered with the results value of "zero but true". A non-zero exit status is handled by failure as in the general case.


Triggered if the code block dies or the forked worker exits abnormally. Recieves the pool object, task id (if provided when calling "pool"), and the error message generated by the code ref.

  my $pool = pool 'thing-doer', ...,
    on failure, call {
      my ($self, $task_id, $error) = @_;
      warn "Error executing task $task_id: $error";

  process { do_things() } $pool, $task_id;



Warnings and limitations for Proc::tored also apply to this module, especially the notes regarding service control from within a running service which also apply to code executing in forked worker processes. See "BUGS AND LIMITATIONS" in Proc::tored for details.


Warnings and limitations for Parallel::ForkManager also apply to this module, including the injunction against using two pools simultaneously from the same process. See "BUGS AND LIMITATIONS" in Parallel::ForkManager and "SECURITY" in Parallel::ForkManager for details.




Jeff Ober <[email protected]>


This software is copyright (c) 2017 by Jeff Ober.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


0.07 March 09, 2017
0.06 March 02, 2017
0.05 February 23, 2017
0.04 February 21, 2017
0.03 February 20, 2017
0.02 February 18, 2017
0.01 February 16, 2017

Project Statistics

SourceRank 6
Dependencies 11
Dependent projects 0
Dependent repositories 0
Total releases 7
Latest release
First release
Stars 0
Forks 0
Watchers 1
Contributors 1
Repo Size: 49.8 KB

Top Contributors See all

Jeff Ober

Something wrong with this page? Make a suggestion

Export .ABOUT file for this library

Last synced: 2017-03-12 08:17:57 UTC

Login to resync this project