[#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:01760] Re: idiom for timeout?

From: Dave Thomas <Dave@...>
Date: 2000-03-06 17:42:52 UTC
List: ruby-talk #1760
The following message is a courtesy copy of an article
that has been posted to comp.lang.misc as well.

Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:

> 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:

You could use lib/timeout.rb:

   require 'timeout'
   status = timeout(5) {
     # something may take time
   }

> (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?

It uses threads, which are more efficient, but the principle's the
same.

Regards

Dave

In This Thread