Scheduling alarms

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

Hi,

···

At Mon, 22 Dec 2003 01:24:06 +0900, Andre Nathan wrote:

(I read some old messages to ruby-talk that said
SIGALRM was “reserved”, because it was used by the interpreter. Is that
true?)

True. I guess you’d better use SIGHUP, SIGUSR1, SIGUSR2 and so
on instead, although I’m not sure what you want to use it for.


Nobu Nakada