- setup_signals(\&kill_pids, \%pids);
- while (@$queue) {
- while (scalar(keys(%pids)) < $max && scalar(@$queue)) {
- my $args = shift @$queue;
- $pids{cb_spawn($cb, $ibxish, $args, $opt)} = $args;
- }
-
- my $flags = 0;
- while (scalar keys %pids) {
- my $pid = waitpid(-1, $flags) or last;
- last if $pid < 0;
- my $args = delete $pids{$pid};
- if ($args) {
- die "E: @$args failed: $?\n" if $?;
- } else {
- warn "unknown PID($pid) reaped: $?\n";
- }
- $flags = WNOHANG if scalar(@$queue);
- }
- }
+ setup_signals(\&kill_pids, $job);
+ $SIG{CHLD} = \&PublicInbox::DS::enqueue_reap;
+ local @PublicInbox::DS::post_loop_do = (\&pids_running, $job);
+ cb_spawn($job, shift(@$queue) // last) for (1..$max);
+ PublicInbox::DS::event_loop;