in reply to Re^2: Parallel::ForkManager run_on_finish exit code handler
in thread Parallel::ForkManager run_on_finish exit code handler
What I was trying to do earlier is use a database handle from run_on_finish()
The child inherited the database handle and closed it. P::FM uses exit when it should probably use POSIX's _exit. finish is simply a call to exec, so if you call _exec instead of finish, that problem should go away.
That means you should replace
withfor(my $i=0; $i< @hosts; $i++){ $pm->start($hosts[$i]) and next; system(@some_command); $return_code = $? >> 8; $pm->finish($return_code); }
use POSIX qw( _exit ); for(my $i=0; $i< @hosts; $i++){ $pm->start($hosts[$i]) and next; system(@some_command); $return_code = $? >> 8; _exit($return_code); }
Of course, system + _exit is a silly way of doing exec, so you get:
for my $host (@hosts) { $pm->start($host) and next; exec(@some_command); }
Error checking added:
for my $host (@hosts) { $pm->start($host) and next; exec(@some_command); print(STDERR "exec failed: $!\n"); _exit($!); }
That also fixes the bug where you'd return zero (success) when the child died from a signal.
Update: Clean up.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parallel::ForkManager run_on_finish exit code handler
by sojourn548 (Acolyte) on Sep 08, 2009 at 19:25 UTC | |
by ikegami (Patriarch) on Sep 09, 2009 at 00:25 UTC |