help with timeout and IO.popen (newb)

W

weathercoach

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top