关于 Ruby 错误处理的小问题。我有一些代码大致类似于以下内容:
urls.each do |url|
begin
threads << Thread.new(url) do |url|
page = open(url)
# some further processing of page
end
rescue
puts "Could not retrieve url"
end
threads.each { |thread| thread.join }
但是,当我运行它时,我偶尔会遇到重定向的 URL,从而产生以下错误:
/usr/lib/ruby/1.8/open-uri.rb:174:in `open_loop': redirection forbidden: // url goes here
from my_file.rb in 'join'
from my_file.rb in 'each'
最后两行是指包含 threads.each 块的代码行。
我只是想知道为什么考虑到我有一个开始救援块我会收到这个错误?我在这里遗漏了什么微妙的东西,也许与多线程有关?