1Parallel::Prefork(3)  User Contributed Perl Documentation Parallel::Prefork(3)
2
3
4

NAME

6       Parallel::Prefork - A simple prefork server framework
7

SYNOPSIS

9         use Parallel::Prefork;
10
11         my $pm = Parallel::Prefork->new({
12           max_workers  => 10,
13           trap_signals => {
14             TERM => 'TERM',
15             HUP  => 'TERM',
16             USR1 => undef,
17           }
18         });
19
20         while ($pm->signal_received ne 'TERM') {
21           load_config();
22           $pm->start(sub {
23               ... do some work within the child process ...
24           });
25         }
26
27         $pm->wait_all_children();
28

DESCRIPTION

30       "Parallel::Prefork" is much like "Parallel::ForkManager", but supports
31       graceful shutdown and run-time reconfiguration.
32

METHODS

34   new
35       instantiation.  Takes a hashref as an argument.  Recognized attributes
36       are as follows.
37
38       max_workers
39
40       number of worker processes (default: 10)
41
42       spawn_interval
43
44       interval in seconds between spawning child processes unless a child
45       process exits abnormally (default: 0)
46
47       err_respawn_interval
48
49       number of seconds to deter spawning of child processes after a worker
50       exits abnormally (default: 1)
51
52       trap_signals
53
54       hashref of signals to be trapped.  Manager process will trap the
55       signals listed in the keys of the hash, and send the signal specified
56       in the associated value (if any) to all worker processes.  If the
57       associated value is a scalar then it is treated as the name of the
58       signal to be sent immediately to all the worker processes.  If the
59       value is an arrayref the first value is treated the name of the signal
60       and the second value is treated as the interval (in seconds) between
61       sending the signal to each worker process.
62
63       on_child_reap
64
65       coderef that is called when a child is reaped. Receives the instance to
66       the current Paralle::Prefork, the child's pid, and its exit status.
67
68   start
69       The main routine.  There are two ways to use the function.
70
71       If given a subref as an argument, forks child processes and executes
72       that subref within the child processes.  The processes will exit with 0
73       status when the subref returns.
74
75       The other way is to not give any arguments to the function.  The
76       function returns undef in child processes.  Caller should execute the
77       application logic and then call "finish" to terminate the process.
78
79       The "start" function returns true within manager process upon receiving
80       a signal specified in the "trap_signals" hashref.
81
82   finish
83       Child processes (when executed by a zero-argument call to "start")
84       should call this function for termination.  Takes exit code as an
85       optional argument.  Only usable from child processes.
86
87   signal_all_children
88       Sends signal to all worker processes.  Only usable from manager
89       process.
90
91   wait_all_children
92       Blocks until all worker processes exit.  Only usable from manager
93       process.
94

AUTHOR

96       Kazuho Oku
97

LICENSE

99       This program is free software; you can redistribute it and/or modify it
100       under the same terms as Perl itself.
101
102       See http://www.perl.com/perl/misc/Artistic.html
103
104
105
106perl v5.12.2                      2010-12-29              Parallel::Prefork(3)
Impressum