I am trying to download a picture with open but it fails on a ratio of about 1 / 500 with a deadlock and I do not know why as I do not use threads at all.
The error is :
/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 />
Here is the function that causes the issue :
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
I am still a beginner in RUBY and do not know how to fix that issue as the only results I get when looking for answers are issues with threads which I am not using.
Any help will be greatly appreciated thank you.