markseger has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to ssh to multiple nodes in parallel via threads and it seems to work just fine. Only problem is when a node doesn't support passwordless ssh things go south.
- why doesn't the signal fire in the thread and
- if it does fire, how do I get rid of the 'unjoined' message at the end?
My solution is to simply wait awhile in a loop, and if the ssh fails kill the thread. I read previous notes about setting up a signal handler in the thread and I tried that and it seems to work just fine. The reason I know this is I have a 'print' in the signal handler and I do see the results. Only problem was when the script eventually exits, it reports:
and I'm not sure what to do. What I did do was write a pretty small script that starts the thread, gives it a few seconds to run, and if the ssh doesn't finish and set a flag, it kills the thread. Only thing is now my signal isn't even firing! So now this is turning into a 2-part question:Perl exited with active threads: 0 running and unjoined 1 finished and unjoined
- why doesn't the signal fire in the thread and
- if it does fire, how do I get rid of the 'unjoined' message at the end?
note - if I use a valid user/hostname the script runs just fine and exits cleanly.#!/usr/bin/perl -w use threads; use threads::shared; my $sshDone:shared; $sshDone=0; my $th=threads->create('test'); $th->join(); sleep 3; if (!$sshDone) { $th->kill('KILL'); print "Kill signal sent\n"; } sleep 2; sub test { $SIG{'KILL'} = sub { print "KILL THREAD\n"; threads->exit(); }; `ssh foo\@poker date`; $sshDone=1; }
what is happening now is I see the echo of the password prompt to the ssh and then nothing! If I remove the join, I see the 'kill signal sent' message but then it just hangs.
gotta be something simple but I'm just not seeing it.
-mark
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: yet another thread/signal question
by BrowserUk (Patriarch) on Nov 06, 2011 at 14:24 UTC | |
by markseger (Beadle) on Nov 06, 2011 at 16:23 UTC | |
by onelesd (Pilgrim) on Nov 06, 2011 at 19:18 UTC | |
by BrowserUk (Patriarch) on Nov 06, 2011 at 19:22 UTC | |
Re: yet another thread/signal question
by zentara (Archbishop) on Nov 06, 2011 at 19:51 UTC |
Back to
Seekers of Perl Wisdom