- Timestamp:
- 09/29/08 13:09:04 (5 years ago)
- Location:
- lang/perl/Parallel-Prefork/trunk
- Files:
-
- 2 modified
-
lib/Parallel/Prefork.pm (modified) (4 diffs)
-
t/01-base.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Parallel-Prefork/trunk/lib/Parallel/Prefork.pm
r18842 r20187 8 8 use Proc::Wait3; 9 9 10 __PACKAGE__->mk_accessors(qw/max_workers err_respawn_interval trap_signals signal_received manager_pid /);10 __PACKAGE__->mk_accessors(qw/max_workers err_respawn_interval trap_signals signal_received manager_pid on_child_reap/); 11 11 12 12 our $VERSION = '0.03'; … … 62 62 } 63 63 if (my ($exit_pid, $status) = wait3(! $pid)) { 64 $self->_run_child_reap_cb( $exit_pid, $status ); 65 64 66 if (delete($self->{worker_pids}{$exit_pid}) == $self->{generation} 65 && $status != 0) {67 && $status != 0) { 66 68 sleep $self->err_respawn_interval; 67 69 } … … 89 91 } 90 92 93 sub _run_child_reap_cb { 94 my ($self, $exit_pid, $status) = @_; 95 my $cb = $self->on_child_reap; 96 if ($cb) { 97 eval { 98 $cb->($self, $exit_pid, $status); 99 }; 100 # XXX - hmph, what to do here? 101 } 102 } 103 91 104 sub wait_all_children { 92 105 my $self = shift; 93 106 while (%{$self->{worker_pids}}) { 94 107 if (my $pid = wait) { 95 delete $self->{worker_pids}{$pid}; 108 if (delete $self->{worker_pids}{$pid}) { 109 $self->_run_child_reap_cb($pid, $?); 110 } 96 111 } 97 112 } … … 152 167 hashref of signals to be trapped. Manager process will trap the signals listed in the keys of the hash, and send the signal specified in the associated value (if any) to all worker processes. 153 168 169 =head3 on_child_reap 170 171 Coderef that is called when a child is reaped. Receives the instance to 172 the current Paralle::Prefork, the child's pid, and its exit status. 173 154 174 =head2 start 155 175 -
lang/perl/Parallel-Prefork/trunk/t/01-base.t
r8848 r20187 6 6 use Fcntl qw/:flock/; 7 7 use File::Temp qw/tempfile/; 8 use Test::More tests => 4;8 use Test::More tests => 5; 9 9 10 10 use_ok('Parallel::Prefork'); 11 11 12 my $reaped = 0; 12 13 my $pm; 13 14 eval { 14 15 $pm = Parallel::Prefork->new({ 15 max_workers => 10, 16 fork_delay => 0, 16 max_workers => 10, 17 fork_delay => 0, 18 on_child_reap => sub { 19 $reaped++; 20 } 17 21 }); 18 22 }; … … 61 65 close $fh; 62 66 is($c, $pm->max_workers * 2); 67 is($reaped, $pm->max_workers, "properly called on_child_reap callback"); 63 68 64 69 unlink $filename;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)