------ art_72790_21332162.1164409227441
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Sorry if I'm bothering you all again... This is my first program that runs
a) threads and b) `system commands`, so I apologize for being a newbie. What
I'm trying to do is ping multiple parts of a site to help an tech support
guy (me) in figuring out where a point of failure is at a remote location.
The reason I'm using threads: I want it to be faster than me typing across
multiple cmd windows. The problem: it's taking 15+ seconds when it works.
I've been tinkering now with it for a few days, and I either get the program
to end in 1 second (killing the child threads before they are done) or I get
the 15 second problem. I'm just not real sure where to put the
Thread.jointo make this run smoothly - nor am I sure that
thread.join is the solution.
Joel VanderWerf suggested mapping stuff, but I'm not doing this by IP
address (his solution the other day involved ping 192.168.1.#{i}) and I
couldn't quite figure out how to modify his code to fit mine.
code (with some stuff obfuscated)
def pingsite(site, type)
result ping -n 4 #{site}-#{type}-1`.chomp
return result
end
puts "What site?"
sitelocation ets.chomp
t0 ime.now
data "
sitetype something", "somethingelse", "again", "more", "otherstuff"]
sitetype.each do |type|
type read.new do
puts pingsite(sitelocation, type)
end
type.join
end
#sitetype.join
t1 ime.now
puts "Finished in #{t1 - t0} seconds"
Output:
Finished in 14.711 seconds
with sitetype.join uncommented and type.join commented, I get this:
What site?
0110
Finished in 1.051 seconds
Can someone explain to me what I'm doing wrong?
------ art_72790_21332162.1164409227441--