Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6627

Re: is timeout.rb fixed in 1.9.2?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!pnx.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: is timeout.rb fixed in 1.9.2?
Date Sat, 29 Sep 2012 18:09:26 +0200
Lines 41
Message-ID <acokpmFgcmpU1@mid.individual.net> (permalink)
References <7cbaac1c-b7eb-4c99-8e58-c6bb896e5319@j14g2000yqb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net 8tJ9VkUTmx4YiV4m9cpNLAiX0Uq0SVKjQTzoi+8ROv0YZnzKOjjRUWY8H/UG7wl2U=
Cancel-Lock sha1:iyHkrRuRQ3p54ms2tHIM+c8GxLc=
User-Agent Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1
In-Reply-To <7cbaac1c-b7eb-4c99-8e58-c6bb896e5319@j14g2000yqb.googlegroups.com>
Xref csiph.com comp.lang.ruby:6627

Show key headers only | View raw


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 | NextPrevious in thread | Find similar


Thread

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