[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01759] idiom for timeout?

From: Hugh Sasse Staff Elec Eng <hgs@...>
Date: 2000-03-06 17:30:39 UTC
List: ruby-talk #1759
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

In This Thread

Prev Next