From: Bill Kelly Date: 2005-08-10T00:12:12+09:00 Subject: Re: Threading+TCPServer issues on Win32 From: "Simon Kr�ger" > > that's the same problem as > > require 'timeout' > timeout(1){ puts gets } > > this will never return (or throw the timeout exception) as > long as you do not hit a key. > Ruby has no native threads, it gets stuck on blocking system > calls. > > I tried to circumvent the problem with Kernel#select, but for > some reason > > select( [$stdin], nil, nil, 1.5 ) > > always returns immediately. Is there someone who can explain? Yes, unfortunately select() on windows only works with sockets. I don't know if this will be of any help, but I've used the following workaround: if WINDOWS_VERSION require 'dl' $win32_console_kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I') def console_input_ready? $win32_console_kbhit.call != 0 end else def console_input_ready? select([$stdin], nil, nil, 0) != nil end end ...it's not foolproof. If you do a gets() when console_input_ready? is true on windows, you'll still block until the user hits . Regards, Bill