From: Gary Watson Date: 2005-12-06T03:08:25+09:00 Subject: Re: limiting how long a method is permiited to run On windows, without having to go to the level of processes or using fork, (as it doesn't work on windows), is there a way to timeout either a call to system or a call using the backtic sytax as in the following logical code which doesn't work? require 'timeout' begin status = Timeout::timeout(1) do `notepad` while(true) puts "this is to fill up the rest of the time" end end rescue Timeout::Error puts "Here is the code from rescue" end puts "And here is code after the begin/end block" ts wrote: >>>>>>"B" == Brian Buckley writes: > > > B> Is there a means of limiting how long a method is permiited to run? I > B> want to be able to mark a method with a number and have the method > B> throw, say, a TooMuchTimeException if the running time exceeds this > B> number. > > Well, you have timeout.rb in the standard distribution > > # = timeout.rb > # > # execution timeout > # > # = Synopsis > # > # require 'timeout' > # status = Timeout::timeout(5) { > # # Something that should be interrupted if it takes too much time... > # } > # > # = Description > # > # A way of performing a potentially long-running operation in a thread, and terminating > # it's execution if it hasn't finished by a fixed amount of time. > # > # Previous versions of timeout didn't provide use a module for namespace. This version > # provides both Timeout.timeout, and a backwards-compatible #timeout. > # > > > > Guy Decoux > >