[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

"Too many open files" error

aldric[removeme]

11/27/2008 11:59:00 PM

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
1 Answer

aldric[removeme]

11/28/2008 12:45:00 AM

0

*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