thread exec

A

Alfonso Caponi

Hi List,

I've a problem with threads using exec, system or similar:

...
...
domains = ['www.bim.com','www.bum.com','www.bam.com']
...
def check (host,domain,timeout)
puts "checking... #{host} -> #{domain}"
timeout(timeout) do
begin
`/usr/bin/nslookup #{domain} #{host}`
rescue Timeout::Error
end
end
end

iplist.each { |host|
threads << Thread.new(host) { |host|
domains.each do |domain|
check(host,domain,timeout)
end
}
}
...

With this code will be check only the first domains of three. Why?

checking... 127.0.0.1 -> www.bim.com
checking... 127.0.0.2 -> www.bim.com
checking... 127.0.0.3 -> www.bim.com
checking... 127.0.0.4 -> www.bim.com
checking... 127.0.0.5 -> www.bim.com
checking... 127.0.0.6 -> www.bim.com
checking... 127.0.0.7 -> www.bim.com
checking... 127.0.0.8 -> www.bim.com
checking... 127.0.0.9 -> www.bim.com

Thank you very much,
Al
 
A

Axel

I think, your script is missing Thread::join:
domains = ['www.bim.com','www.bum.com','www.bam.com']
..
def check (host,domain,timeout)
  puts "checking... #{host} -> #{domain}"
  timeout(timeout) do
   begin
    `/usr/bin/nslookup #{domain} #{host}`
   rescue Timeout::Error
   end
  end
end

iplist.each { |host|
 threads << Thread.new(host) { |host|
  domains.each do |domain|
   check(host,domain,timeout)
  end
 }}

threads.each {|th|
th.join
}

(Not tested.)

-Axel
 
A

Alfonso Caponi

Axel said:
I think, your script is missing Thread::join:


threads.each {|th|
th.join
}

(Not tested.)

-Axel

ops! :)

Thank you very much! It seem works fine now :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top