From: pit@... Date: 2001-06-16T17:45:30+09:00 Subject: [ruby-talk:16531] Re: alarm() On 16 Jun 2001, at 12:36, Dave Thomas wrote: > Joseph McDonald writes: > > > Is there a way to schedule a SIGALRM in ruby? > > I ask because I want to abort a system() call if > > it does not complete in "x" seconds. It appears that > > the "timeout" class does not work when executing a > > system call. > > Tacky, but you could start a thread that sends you a SIGALRM: > > Thread.new do > sleep 2 > Process.kill "ALRM", $$ > end > > begin > line = gets > puts "You said #{line}" > rescue SignalException > puts "too slow!" > end > > > Regards > > > Dave FYI, I tried Dave's example on Win NT and ruby 1.6.2 (2000-12-18) [i386-cygwin]. It works almost as expected, but when I press a key in the first two seconds and then wait, the gets is not interrupted at all.