in reply to Re^2: Parallel::Forkmanager question
in thread Parallel::Forkmanager question
Hello again jamesgerard1964,
One might find useful the exit_status from each system call. The MCE::Shared module is helpful in that regard.
On purpose, am making a slight change to using MCE::Loop. The comma is needed after the sub { ... } block before @servers. Basically, am calling three methods: ->init to configure MCE options, ->run to run the code block, and finally ->finish to shutdown and reap workers. Afterwards, like to see the system status captured into the shared hash.
use strict; use warnings; use MCE::Loop; use MCE::Shared; my @servers = ('a'..'z'); my $timeout = 10; my $user = "foo"; my $file = "/tmp/hello.txt"; my $rpath = "/tmp"; my $fname = "hello.txt"; tie my %result, 'MCE::Shared'; MCE::Loop->init( chunk_size => 1, max_workers => 8, ); MCE::Loop->run( sub { my $server = $_; MCE->say("child process running, with a key of $server ($$)"); eval { local $SIG{ALRM} = sub { alarm 0; die "alarm\n" }; alarm $timeout; $result{$server} = system("scp -p $file $user\@$server:$rpath/$fn +ame"); }; alarm 0; }, @servers ); MCE::Loop->finish; for my $server ( sort keys %result ) { my ($status, $signum); $status = $result{$server}; $signum = $status & 127; # extract signal number $status = $status >> 8; # becomes exit status print "$server: exit_status $status, signal_num $signum\n"; }
Thank you for reaching out to Perlmonks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parallel::Forkmanager question
by Anonymous Monk on Apr 06, 2017 at 02:44 UTC |