Project

General

Profile

Actions

Backport #8187

closed

timeout doesn't interrupt assignment.

Added by robertgleeson (Robert Gleeson) about 11 years ago. Updated about 11 years ago.

Status:
Rejected
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

Updated by robertgleeson (Robert Gleeson) about 11 years ago

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

Updated by robertgleeson (Robert Gleeson) about 11 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.

Updated by robertgleeson (Robert Gleeson) about 11 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.

Updated by robertgleeson (Robert Gleeson) about 11 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.

Updated by kosaki (Motohiro KOSAKI) about 11 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 '

Updated by kosaki (Motohiro KOSAKI) about 11 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0