Sorry to be rude, but you really don't seem to have a clue what you are doing.
This is a completely redundant use of threading:
push (@threads, threads->new(\&Process_Output, $ssh, $proc )); while ( $thread = shift @threads ) { @output=$thread->join(); }
You create a thread and push its handle onto @threads. You then immediately shift that handle off of the array and join it.
It is exactly equivalent to:
$thread = threads->new(\&Process_Output, $ssh, $proc ); if( $thread ) { @output = $thread->join(); }
Which is equivalent to :
$thread = threads->new(\&Process_Output, $ssh, $proc ); @output = $thread->join();
Which is exactly equivalent to this:
@output = threads->new(\&Process_Output, $ssh, $proc )->join();
Which is exactly equivalent to:
@output = Process_Output( $ssh, $proc );
Except that the latter will work. (Of course, it won't speed things up. But neither will what you have now.) But it will work.
The reason your code is crashing is because you are creating an instance of Net::SSH::Expect in one thread, and trying to use it in another.
Why? Why not create the object in the thread where you are going to use it?
In reply to Re^3: Need help with Perl multi threading
by BrowserUk
in thread Need help with Perl multi threading
by ashok.g
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |