From: Colin Bartlett on
[* same post as just made, but this time I've remembered to add the code *]

On Fri, Mar 26, 2010 at 11:59 AM, Rico Knoop <jointgek(a)gmail.com> wrote:

> it didn't seem to work,
> it just kept waiting for me to input something.
> i even tried to run just that code.
> its still blinking, waiting for input on the background.
>
> am i doing something wrong?

It might depend on which operating system and/or Ruby version you are using.
I tried the code underneath on Windows Vista, using the Ruby Windows versions,
and Ruby. It works for me using Ruby 1.9 for Windows.
But using Ruby 1.8.6 and using the JRuby 1.8 equivalent seemed to work,
or rather not work, in the way you described in your latest post.

Colin Bartlett

require "timeout"
def gets_timeout( prompt, secs )
puts
print prompt + "[timeout=#{secs}secs]: "
Timeout::timeout( secs ) { gets }
rescue Timeout::Error
puts "*timeout"
nil # return nil if timeout
end

rr = gets_timeout "Do not input. Wait for timeout. ", 5
p rr #=> nil
rr = gets_timeout "Input something before timeout: ", 10
p rr #=> "something\n"

From: Jesús Gabriel y Galán on
On Fri, Mar 26, 2010 at 4:23 PM, Colin Bartlett <colinb2r(a)googlemail.com> wrote:
> On Fri, Mar 26, 2010 at 11:59 AM, Rico Knoop <jointgek(a)gmail.com> wrote:
>
>> it didn't seem to work,
>> it just kept waiting for me to input something.
>> i even tried to run just that code.
>> its still blinking, waiting for input on the background.
>>
>> am i doing something wrong?
>
> It might depend on which operating system and/or Ruby version you are using.
> I tried the code underneath on Windows Vista, using the Ruby Windows versions,
> and Ruby. It works for me using Ruby 1.9 for Windows.
> But using Ruby 1.8.6  and using the JRuby 1.8 equivalent seemed to work,
> or rather not work, in the way you described in your latest post.

I tested my version in Ubuntu and it worked fine.

Jesus.

From: Charles Oliver Nutter on
On Fri, Mar 26, 2010 at 10:23 AM, Colin Bartlett
<colinb2r(a)googlemail.com> wrote:
> It might depend on which operating system and/or Ruby version you are using.
> I tried the code underneath on Windows Vista, using the Ruby Windows versions,
> and Ruby. It works for me using Ruby 1.9 for Windows.
> But using Ruby 1.8.6  and using the JRuby 1.8 equivalent seemed to work,
> or rather not work, in the way you described in your latest post.

At least for JRuby, we can't do a proper select on stdio because the
JVM does not provide such a capability. So timeout can't interrupt
stdio.

- Charlie