Bug #7088

Documentation of Timeout::timeout is wrong about which thread executes the block

Added by Robert Klemme over 1 year ago. Updated over 1 year ago.

[ruby-core:47739]
Status:Closed
Priority:Normal
Assignee:Zachary Scott
Category:doc
Target version:2.0.0
ruby -v:ruby 1.9.3p194 (2012-04-20) [i686-linux] Backport:

Description

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
end

Note: this avoids bug #4285 at the expense of a potentially longer running thread. Killing the background thread would suffer the same issues.

Associated revisions

Revision 37145
Added by Zachary Scott over 1 year ago

  • lib/timeout.rb (timeout): Remove paragraph on wrong implementation detail. [Bug #7088]

History

#1 Updated by Eric Hodel over 1 year ago

  • Category set to doc
  • Target version set to 2.0.0

#2 Updated by Zachary Scott over 1 year ago

  • Assignee set to Zachary Scott

#3 Updated by Zachary Scott over 1 year ago

How about we change that to: "The block will be executed on the current thread and will be given one argument: sec. While, the timer for sec number of seconds will run in another thread".

#4 Updated by Eric Hodel over 1 year ago

I think deleting the paragraph would be sufficient. We don't need to reveal the implementation details of timeout.

#5 Updated by Zachary Scott over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37145.
Robert, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/timeout.rb (timeout): Remove paragraph on wrong implementation detail. [Bug #7088]

Also available in: Atom PDF