Help with timeout and IO.popen (newb)

Hello Folks. I’m running ruby 1.8.6 on Solaris 10 i86pc.

I have a script where I use IO.popen to execute some system
commands. I want to timeout the execution of the system commands if
they take too long to execute. So I read about the timeout library
and have been playing with that. However I think I am missing
something.

In this example I felt I was setting the timeout to 5 seconds and
that the script will continue down it’s execution path if the command
called within IO.popen takes longer than 5 seconds

require ‘timeout’

begin
timeout(5) {
IO.popen("/usr/bin/sleep 10") {|f|
exit_code = Process.waitpid2(f.pid)[1] >> 8
}
}
rescue Timeout::Error
puts “timed out”
end

However upon execution the timeout never occurs and the rescue
clause is executed?

time ./timeouttest1
timed out

real 0m10.020s
user 0m0.007s
sys 0m0.007s

I’ve read the timout documentation and poked through the timeout.rb
file but I still don’t understand what I’m missing. Any tips are
appreciated.
TIA. G.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs