Hi
I’m trying to find out how to schedule alarms in ruby, as in the alarm(2)
function on Unix.
Google found a post by Dave Thomas from 2001 [ruby-talk:16527] which
sugests the use of a thread to schedule the alarm. Is this still the
prefered way to do this?
Thanks
Andre
Hi,
At Sun, 21 Dec 2003 13:24:50 +0900,
Google found a post by Dave Thomas from 2001 [ruby-talk:16527] which
sugests the use of a thread to schedule the alarm. Is this still the
prefered way to do this?
You can also use timeout.rb.
require ‘timeout’
begin
Timeout.timeout(2) do
line = gets
puts “You said #{line}”
end
rescue Timeout::Error
puts “too slow!”
end
···
–
Nobu Nakada
nobu.nokada@softhome.net said:
You can also use timeout.rb.
This will probably be fine for what I need, but it would be nice to have a
way
to activate the alarm independently from the timeout specified on the script
(as in `kill -ALRM foo.rb’). Is there a reason why this isn’t possible or
it’s
just not implemented yet? (I read some old messages to ruby-talk that said
SIGALRM was “reserved”, because it was used by the interpreter. Is that
true?)
Thanks
Andre