From: Zach Buckholz Date: 2007-02-13T02:31:45+09:00 Subject: Ruby thread question I have a script that goes thru each server in the environment and updates a database with the current rpm package info. It's used for tracking, to make sure all servers have the same versions etc. and query when something has changed. It's been successful for about 1 year now, but as the environment has grown it takes longer to complete so I am trying to use ruby threads to fire off multiple server checks at the same time. I added what I believe is the correct logic below, but this does not seem to work. All servers get their own thread, and start running. But as soon as one completes the entire script exists as if it has completed successfully. Any insight would be appreciated. Thanks Zach #!/usr/local/bin/ruby require 'thread' require "servers" require 'net/ssh' require 'rpmlist' require 'rpmmysql' require 'rpm' class RPMAudit serversObj = Servers.new() threads = [] serversObj.all.each { |x| threads << Thread.new(x) { |y| hostName = y[1] + "." + y[2] print "HOSTNAME : ", hostName, " started:\n" result = RPMList.new(hostName) if(result.rpmArray == nil) then next end rpmThreads = [] result.rpmArray.each { |y| rpmThreads << Thread.new(y) { |z| package = RPM.new( z ) if(package.signature == nil) then next end print "." STDOUT.flush sql = RPMMysql.new(package,hostName) } rpmThreads.each { |bthread| bthread.join } } print "HOSTNAME : ", hostName, " ended:\n" } } threads.each { |aThread| aThread.join } end