루비에서 Timeout
모듈을 발견하여 테스트하고 싶었습니다. 내가 http://ruby-doc.org/stdlib-2.1.1/libdoc/timeout/rdoc/Timeout.html 여기Ruby Timeout Module - Timeout이 실행되지 않습니다.
에서 자신의 공식 소스 코드를 보면서 나는 몇 가지 벤치 마크 테스트를했다
require 'timeout'
require 'benchmark'
numbers = [*1..80]
Timeout::timeout(5) { numbers.combination(5).count }
=> 24040016
있었고, 다음을 가지고 코드입니다.
10.828000 0.063000 10.891000 11.001676
문서에 따르면이 메서드는 블록이 5 초 내에 실행되지 않으면 예외를 반환한다고 가정합니다. 시간 프레임 내에서 실행되면 코드 블록의 결과를 반환합니다.
5 초가 아닌 1 초로 타임 아웃을 시도했는데 여전히 결과가 반환됩니다. 코드 블록.
는 여기이 작동하지 않는 이유에 신비화 오전 공식 문서
timeout(sec, klass=nil)
Performs an operation in a block, raising an error if it takes longer than sec seconds to complete.
sec: Number of seconds to wait for the block to terminate. Any number may be used,
including Floats to specify fractional seconds. A value of 0 or nil will execute the
block without any timeout.
klass: Exception Class to raise if the block fails to terminate in sec seconds. Omitting
will use the default, Timeout::Error
입니다.