Project

General

Profile

Backport #8187

timeout doesn't interrupt assignment.

Added by Robert Gleeson almost 3 years ago. Updated almost 3 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
[ruby-core:53835]

Description

Timeout does not interrupt & raise like usual with this example code:

require 'timeout'
Timeout.timeout(0.5) do
x = " "(2*31)
end

History

#1 [ruby-core:53836] Updated by Robert Gleeson almost 3 years ago

I should have said that this code might exhaust your RAM, so don't let it run too long.

#2 [ruby-core:53837] Updated by Robert Gleeson almost 3 years ago

For my case, this code was run in a subprocess. Instead of using Timeout in the subprocess, I use it from the parent instead, like this:

pid = fork { x = " "(2*31) }
begin
Timeout.timeout(1) do
Process.wait pid
end
rescue Timeout::Error
Process.kill 'SIGKILL', pid
Process.wait pid
end

This solves the problem for me.

#3 [ruby-core:53840] Updated by Robert Gleeson almost 3 years ago

Tested against:
- ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]
- ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.2]

The behavior on 1.9.3 is to hang without being able to interrupt, and the behavior
on 2.0.0 appears to execute the code, stop it, and exit without raising an exception.

#4 [ruby-core:54406] Updated by Robert Gleeson almost 3 years ago

I opened this bug on Rubinius(https://github.com/rubinius/rubinius/issues/2287) and it looks like there's no way to interrupt this code. Please close.

#5 [ruby-core:54409] Updated by Motohiro KOSAKI almost 3 years ago

I couldn't reproduce.

% ruby -v test.rb
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
/home/kosaki/ruby/git/test.rb:3: warning: assigned but unused variable - x
/home/kosaki/ruby/git/test.rb:3:in *': failed to allocate memory (NoMemoryError)
from /home/kosaki/ruby/git/test.rb:3:in
block in '
from /home/kosaki/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/timeout.rb:65:in timeout'
from /home/kosaki/ruby/git/test.rb:2:in
'

#6 [ruby-core:54410] Updated by Motohiro KOSAKI almost 3 years ago

  • Status changed from Open to Rejected

Also available in: Atom PDF