is timeout.rb fixed in 1.9.2?

R

Robert Klemme

Greetings,

I've got Net::HTTP.get calls going against a dev server that's
responding very slowly and I've been told that I should set my timeout
at about 5 minutes. In googling how to do that I came across a link
to this: http://headius.blogspot.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html
So I thought I should ask.

You can check for yourself:
https://bugs.ruby-lang.org/issues/4285

Note, while looking into this I opened a few bugs today:
https://bugs.ruby-lang.org/issues/7086
https://bugs.ruby-lang.org/issues/7087
https://bugs.ruby-lang.org/issues/7088

:)

My solution timeout_1 could be used but it will keep the background
thread running. You could change it like so:

def timeout_5(timeout, &code)
raise ArgumentError, "Invalid timeout: %p" % [timeout] unless timeout > 0
raise ArgumentError, "No code to execute" if code.nil?

worker = Thread.new(&code)

if worker.join(timeout)
worker.value
else
worker.kill rescue nil
# worker.raise Exception, "Stop"
nil
end
end


Kind regards

robert
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top