Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6627
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: is timeout.rb fixed in 1.9.2? |
| Date | 2012-09-29 18:09 +0200 |
| Message-ID | <acokpmFgcmpU1@mid.individual.net> (permalink) |
| References | <7cbaac1c-b7eb-4c99-8e58-c6bb896e5319@j14g2000yqb.googlegroups.com> |
On 09/28/2012 08:59 PM, bill walton wrote:
> 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
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
is timeout.rb fixed in 1.9.2? bill walton <bwalton.im@gmail.com> - 2012-09-28 11:59 -0700 Re: is timeout.rb fixed in 1.9.2? Robert Klemme <shortcutter@googlemail.com> - 2012-09-29 18:09 +0200
csiph-web