<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>tmtms</author_name>
  <author_url>https://blog.hatena.ne.jp/tmtms/</author_url>
  <blog_title>tmtms のメモ</blog_title>
  <blog_url>https://blog.tmtms.net/</blog_url>
  <categories>
    <anon>Ruby</anon>
  </categories>
  <description>Ruby で長い時間掛かるかも知れない処理のタイムアウトを行うにはこんな感じにします。 require 'timeout' begin Timeout.timeout(3) do # 3秒でタイムアウト hoge # 何かの処理 end rescue Timeout::Error puts 'なげーよ' # タイムアウト発生時の処理 end Timeout.timeout はブロック開始時にスレッドを作成し、そのスレッドで指定された秒数だけ sleep して、sleep から復帰してもまだブロックが終わってなければ作成元のスレッドに対して Timeout::Error 例外を発生させます。 指…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.tmtms.net%2Fentry%2F2016%2F08%2F25%2Fruby-timeout&quot; title=&quot;Ruby の Timeout の仕組み - tmtms のメモ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2016-08-25 23:57:46</published>
  <title>Ruby の Timeout の仕組み</title>
  <type>rich</type>
  <url>https://blog.tmtms.net/entry/2016/08/25/ruby-timeout</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
