るりまサーチ

最速Rubyリファレンスマニュアル検索!
19件ヒット [1-19件を表示] (0.047秒)
トップページ > クエリ:nil[x] > クエリ:end[x] > クエリ:line[x] > モジュール:Timeout[x]

別のキーワード

  1. _builtin nil?
  2. nilclass nil?
  3. object nil?
  4. _builtin nil
  5. object nil

ライブラリ

検索結果

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

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

...を過ぎたときは例外
Timeout
::Error が発生します。

exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはいります。

また sec が 0 もしくは nil のときは制限時間なし...
...
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:...
...gin
pid = nil
com = nil
Timeout
.timeout(t) {
# system だととまらない
# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end

}
rescue Timeout::Error => err
puts "timeout: shell execu...

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

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

...を過ぎたときは例外
Timeout
::Error が発生します。

exception_class を指定した場合には Timeout::Error の代わりに
その例外が発生します。
ブロックパラメータ i は sec がはいります。

また sec が 0 もしくは nil のときは制限時間なし...
...
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:...
...gin
pid = nil
com = nil
Timeout
.timeout(t) {
# system だととまらない
# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end

}
rescue Timeout::Error => err
puts "timeout: shell execu...