るりまサーチ (Ruby 3.4)

最速Rubyリファレンスマニュアル検索!
2件ヒット [1-2件を表示] (0.021秒)
トップページ > バージョン:3.4[x] > クエリ:Object[x] > ライブラリ:timeout[x]

別のキーワード

  1. _builtin each_object
  2. objectspace each_object
  3. json object
  4. object then
  5. object send

モジュール

検索結果

Timeout.#timeout(sec, exception_class = nil) {|i| ... } -> object (313.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 [c:Timeout::Error] が発生します。

...の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
[c:Timeout::Error] が発生します。

exception_class を指定した場合には [c:Timeout::Error] の代わりにその例外が発生します。
ブロックパラメータ i は sec がは...
...のタイムアウト"
require 'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t = 5
min = [ 0, 0]
begin
Timeout
.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end

printf "%d: pi = %f\n", min[0...
...n[1])
#例
# => 417519: pi = 3.141443
```

```ruby title="例 独自の例外を発生させるタイムアウト"
#!/usr/bin/env ruby

require 'timeout'

class MYError < Exception;end
begin
Timeout
.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
```...

Timeout.#timeout(sec, exception_class, message) {|i| ... } -> object (313.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 [c:Timeout::Error] が発生します。

...の期限付きで実行します。
ブロックの実行時間が制限を過ぎたときは例外
[c:Timeout::Error] が発生します。

exception_class を指定した場合には [c:Timeout::Error] の代わりにその例外が発生します。
ブロックパラメータ i は sec がは...
...のタイムアウト"
require 'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t = 5
min = [ 0, 0]
begin
Timeout
.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end

printf "%d: pi = %f\n", min[0...
...n[1])
#例
# => 417519: pi = 3.141443
```

```ruby title="例 独自の例外を発生させるタイムアウト"
#!/usr/bin/env ruby

require 'timeout'

class MYError < Exception;end
begin
Timeout
.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end
```...