<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Slash Dot Dash: Ruby Tidbit: Timeout code execution</title>
    <link>http://www.slashdotdash.net/articles/2008/02/15/ruby-tidbit-timeout-code-execution</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Rolling on Rails</description>
    <item>
      <title>Ruby Tidbit: Timeout code execution</title>
      <description>&lt;p&gt;Just a small tip, if you wish to ensure a snippet of Ruby code doesn&amp;#8217;t run for too long you can use the timeout function. You might want to do this when making a request to a remote server with &lt;code&gt;net/http&lt;/code&gt; for example.&lt;/p&gt;


&lt;a href="http://www.ruby-doc.org/stdlib/libdoc/timeout/rdoc/index.html"&gt;timeout.rb&lt;/a&gt;
	&lt;blockquote&gt;
		&lt;p&gt;A way of performing a potentially long-running operation in a thread, and terminating it&#8216;s execution if it hasn&#8216;t finished within fixed amount of time.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Here&amp;#8217;s a quick example using the excellent &lt;a href="http://rfeedparser.rubyforge.org/"&gt;rFeedParser&lt;/a&gt; (Universal Feed Parser in Ruby) to fetch an &lt;span class="caps"&gt;RSS&lt;/span&gt; feed.&lt;/p&gt;


&lt;pre&gt;
require 'timeout'
require 'zlib'
require 'rubygems'
require 'rfeedparser'

fp = nil
begin
  # Don't take longer than 20 seconds to retrieve &amp;#38; parse an RSS feed
  Timeout::timeout(20) do
    fp = FeedParser.parse("http://feeds.feedburner.com/slashdotdash")
  end
rescue Timeout::Error
  # Too slow!!
end
&lt;/pre&gt;</description>
      <pubDate>Fri, 15 Feb 2008 00:39:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4fb9acf2-d6a0-497e-abe0-edaab6ab76f4</guid>
      <author>ben@slashdotdash.net (Ben)</author>
      <link>http://www.slashdotdash.net/articles/2008/02/15/ruby-tidbit-timeout-code-execution</link>
      <category>Ruby on Rails</category>
      <category>ruby</category>
    </item>
    <item>
      <title>"Ruby Tidbit: Timeout code execution" by David Roussel</title>
      <description>&lt;p&gt;timeout is unsafe.&lt;/p&gt;


	&lt;p&gt;See &lt;a href="http://headius.blogspot.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html" rel="nofollow"&gt;http://headius.blogspot.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 29 Feb 2008 14:42:33 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:9d0b69c9-fe9c-41e0-a1cd-3a0ff0eb670a</guid>
      <link>http://www.slashdotdash.net/articles/2008/02/15/ruby-tidbit-timeout-code-execution#comment-382</link>
    </item>
  </channel>
</rss>
