From: Hugh Sasse Staff Elec Eng Date: 2000-03-06T17:30:39+00:00 Subject: [ruby-talk:01759] idiom for timeout? Is there a correct Ruby idiom for timing out an operation? There seems to be no alarm function in Ruby, so I cannot do it the Perl way: $SIG{ALRM} = sub { die "timeout" }; eval { alarm(3600); # long-time operations here alarm(0); }; if ($@) { if ($@ =~ /timeout/) { # timed out; do what you will here } else { die; # propagate unexpected exception } } (to quote the Perl Cookbook). I suppose one could do it with a call to fork, have the parent send signal 0 to the child to see if it still lives, and repeat this every (short time) until the child dies or the timeout is reached. If I can do this without the fork it would be better though. Is there a better way? Thank you, Hugh hgs@dmu.ac.uk