The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Parallel::Boss - manage worker processes

VERSION

This document describes Parallel::Boss version 0.03

SYNOPSIS

    use Parallel::Boss;

    my $worker = sub {
        my ( @args ) = @_;
        # pretend to be working
        ...;
    };

    Parallel::Boss->run(
        num_workers  => 4,
        args         => \@args,
        exit_timeout => 15,
        worker       => $worker,
    );

DESCRIPTION

Module running specified number of worker processes.

METHODS

run

     $class->run(%params)

start specified number of workers and supervise them. If any of the workers exits, a new one will be started as a replacement. If parent process receives HUP signal, then it sends HUP signal to every worker process and restarts workers if they exit. If parent process receives INT, QUIT, or TERM, it sends TERM to all workers, waits for up to exit_timeout seconds till they all exit, and sends KILL to those workers that are still running, after all workers exited the run method returns. Each worker process runs watchdog thread that detects if the parent process has died and terminates the worker by sending it first SIGTERM and then calling _exit(2) after exit_timeout seconds if the worker is still running.

The following parameters are accepted:

num_workers

number of workers to start

args

reference to array of arguments that should be passed to worker subroutine

exit_timeout

when parent process signalled to exit it first sends to all workers SIGTERM. If exit_timeout is set and greater than zero then after exit_timeout workers that are still running are sent SIGKILL.

worker

subroutine that will be executed by every worker. If it returns, the worker process exits. The args array is passed to subroutine as the list of arguments.

AUTHOR

Pavel Shaydo <zwon at cpan.org>

LICENSE AND COPYRIGHT

Copyright (C) 2016 Pavel Shaydo

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.