From: daz Date: 2004-04-29T09:14:02+09:00 Subject: Re: DRb & thread blocking. > > If anyone knows the work-around to this, please add. > Hope this is of general use for STDIN#gets in a thread. It checks for input in the keyboard buffer and if there is any, does a normal (blocking) STDIN#gets. # STDIN#wt_gets for Windows # Doesn't block threads until there's input. # Won't run from GUIs (e.g. RDE, SciTE ...) # (see kbhit API docs.) require 'Win32API' W_kbhit = Win32API.new('msvcrt', '_kbhit', '', 'I') def STDIN.key_wait while W_kbhit.call == 0; sleep 0.1; end end def STDIN.wt_gets key_wait gets end #----- Usage ... STDOUT.sync = true Thread.new do loop do puts Time.now sleep 1 end end Thread.new do loop do inp = STDIN.wt_gets.chomp! inp.upcase == 'EXIT' and Thread.exit puts inp end end.join puts "\n\nPress a key to really exit ...\n\n" STDIN.key_wait # defined above #---------- I tried a VRuby GUI solution but it became a bit too feature-packed. Couldn't hold myself back :-) daz