Documentation of Timeout::timeout is wrong about which thread executes the block
See http://rubydoc.info/stdlib/timeout/Timeout#timeout-class_method - it reads "The block will be executed on another thread and will be given one argument: sec." If you make the source code visible or look into the file timeout.rb in the library you'll see that the block is invoked from the current (calling) thread. The comment reads as if the author had wanted to do an implementation like this:
def timeout_1(timeout, &code)
raise ArgumentError, "Invalid timeout: %p" % [timeout] unless timeout > 0
raise ArgumentError, "No code to execute" if code.nil?
worker = Thread.new(&code)
worker.join(timeout) and worker.value
Note: this avoids bug #4285 at the expense of a potentially longer running thread. Killing the background thread would suffer the same issues.
- lib/timeout.rb (timeout): Remove paragraph on wrong implementation detail. [ruby-core:47739] [Bug #7088]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37145 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Updated by zzak (Zachary Scott) over 6 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100