ruby:打开'join':没有活动线程。僵局? (致命)

时间:2016-05-22 21:34:49

标签: ruby deadlock open-uri

我正在尝试下载一张打开的图片但它失败的比例大约是1/500与死锁,我不知道为什么我根本不使用线程。

错误是:

/usr/lib/ruby/2.3.0/timeout.rb:95:in 'join': No live threads left. Deadlock? (fatal)<br />
from /usr/lib/ruby/2.3.0/timeout.rb:95:in 'ensure in block in timeout'<br />
from /usr/lib/ruby/2.3.0/timeout.rb:95:in 'block in timeout'<br />
from /usr/lib/ruby/2.3.0/timeout.rb:101:in 'timeout'<br />
from /usr/lib/ruby/2.3.0/net/http.rb:878:in 'connect'<br />
from /usr/lib/ruby/2.3.0/net/http.rb:863:in 'do_start'<br />
from /usr/lib/ruby/2.3.0/net/http.rb:852:in 'start'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:319:in 'open_http'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:737:in 'buffer_open'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:212:in 'block in open_loop'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:210:in 'catch'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:210:in 'open_loop'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:151:in 'open_uri'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:717:in 'open'<br />
from /usr/lib/ruby/2.3.0/open-uri.rb:35:in 'open'<br />
from /home/mat/travail_perso/utils.rb:80:in get_pic'<br />

以下是导致问题的函数:

def get_pic(link)
  tries ||= 25
  begin
    page = open(link, "User-Agent" => "Ruby/#{RUBY_VERSION}")
  rescue => error
    if tries > 0
        tries -= 1
        sleep(0.75)
        retry
    else
      puts 'could nor get picture ' + link + ' after ' + $nb_tries.to_s + ' tries'
      puts error.message
      return nil
    end
  end
  sleep(0.25)
  return page
end

我仍然是RUBY的初学者,并且不知道如何解决这个问题,因为我在寻找答案时得到的唯一结果是我没有使用的线程问题。
非常感谢任何帮助。谢谢。

0 个答案:

没有答案