"Too many open files" error

A

Aldric Giacomoni

Example code, on Ruby 1.8.6:
require 'resolv'
t0 = Time.now
(1..500).each do |a|
begin
a = Resolv::DNS.new.getaddress("www.example.dom").to_s
rescue Resolv::ResolvError
a = "Hahahahaa"
end
end
puts "#{(Time.now - t0) / 500} second per."

Error:
c:/ruby/lib/ruby/1.8/resolv.rb:572:in `initialize': Too many open files
(Errno::EMFILE)
___________________

How can I prevent this error from happening? Can I do manual garbage
collection and delete each DNS.new Object at the end of each iteration?
Is there a better idea out there?

Thanks,

--Aldric
 
A

Aldric Giacomoni

*sigh* Never mind, I was being stupid - just create one object and then
reuse that object over and over as needed! Unless I absolutely need to
create more objects.. Let's not do that.

--Aldric
 

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
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top