Does calling Net::SSH.start(...) inside of a thread block other
threads from executing?
Given a code like this:
===========threads = []
$machineList.each{|mach|
threads << Thread.new(mach) {|guest|
puts "Connnecting to #{guest}"
Net::SSH.start(guest,
:password=>$pass,
:username=>$user) { |session|
puts "Connected. Initiating run of executable..."
$pathToExecutable = "/tmp/runTenTimes.sh \n"
run_executable(session, $pathToExecutable, "")
session.loop
}
}
threads.each {|t| t.join }
}
def run_executable (session, executable, args)
session.open_channel do |channel|
channel.on_data do |ch, data|
puts "[#{ch}] ==> #{data}"
end
channel.on_failure do |ch|
puts "#{ch} failed"
end
channel.on_success do|ch|
puts "#{ch} successfully opened"
end
channel.exec "#{executable} #{args}"
end
end
==========
I get the output from each machine in serial order! That is, the
script runs on machine1 for about all of 10 seconds, before the second
thread even starts off connecting to the second machine. Is there a
way to ensure that threads run concurrently?
-Vivek
Never mind. I figured it out.
The call to:
threads.each {|t| t.join }
should''ve been after the block for $machineList.eachP{|mach|
Yeccch. Sorry about the silliness.
-Vivek
On 05/02/07, Vivek Nallur <nallur at gmail.com>
wrote:> Does calling Net::SSH.start(...) inside of a thread block other
> threads from executing?
>
> Given a code like this:
> ===========> threads = []
> $machineList.each{|mach|
> threads << Thread.new(mach) {|guest|
> puts "Connnecting to #{guest}"
> Net::SSH.start(guest,
> :password=>$pass,
> :username=>$user) { |session|
> puts "Connected. Initiating run of executable..."
> $pathToExecutable = "/tmp/runTenTimes.sh \n"
> run_executable(session, $pathToExecutable, "")
> session.loop
> }
> }
> threads.each {|t| t.join }
> }
>
> def run_executable (session, executable, args)
> session.open_channel do |channel|
> channel.on_data do |ch, data|
> puts "[#{ch}] ==> #{data}"
> end
> channel.on_failure do |ch|
> puts "#{ch} failed"
> end
> channel.on_success do|ch|
> puts "#{ch} successfully opened"
> end
> channel.exec "#{executable} #{args}"
> end
> end
> ==========>
> I get the output from each machine in serial order! That is, the
> script runs on machine1 for about all of 10 seconds, before the second
> thread even starts off connecting to the second machine. Is there a
> way to ensure that threads run concurrently?
>
> -Vivek
>