# Non-blocking gets in Windows

**URL:** <https://www.ruby-forum.com/t/non-blocking-gets-in-windows/157032>\
**Category:** Ruby\
**Created:** [January 6, 2009, 5:33pm UTC](https://www.ruby-forum.com/t/non-blocking-gets-in-windows/157032 "2009-01-06T17:33:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![king\_duckz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58f4c7/32.png) [@king\_duckz](https://www.ruby-forum.com/u/king_duckz)\
**Post date:** [January 6, 2009, 5:33pm UTC](https://www.ruby-forum.com/t/non-blocking-gets-in-windows/157032/1 "2009-01-06T17:33:42Z")

</div>

Hello, I know this topic has already been discussed here a while ago,  
but I was wondering if anyone came up with a workaround or something.  
I’m trying to write a script that checks email every - say - 10 minutes,  
while still accepting user’s input, so that one can stop it.  
This code works perfectly under linux:

def Prova1  
running = true  
th = Thread.new do  
while running  
inp = gets.chomp  
running = false if [“QUIT”, “EXIT”].include?(inp.upcase)  
puts “Ho ricevuto “#{inp}”…”  
end  
end  
until th.join(0.5)  
puts “Attesa…”  
sleep 1  
end  
nil  
end

but if run under Windows, the whole script stops as soon as “gets” is  
reached, as if it was single-threaded.

---

<div class="post-metadata">

**Author:** ![king\_duckz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58f4c7/32.png) [@king\_duckz](https://www.ruby-forum.com/u/king_duckz)\
**Post date:** [January 6, 2009, 11:12pm UTC](https://www.ruby-forum.com/t/non-blocking-gets-in-windows/157032/2 "2009-01-06T23:12:44Z")

</div>

From: “Duckz King\_duckz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> but if run under Windows, the whole script stops as soon as “gets” is  
> reached, as if it was single-threaded.

I believe this works in ruby 1.9.1, now that native threads are used.

(I tested IO.popen on 1.9.1 on windows a few days ago, and finally all  
of ruby is not blocked by a gets on the pipe. Yay!)

In ruby 1.8 and earlier, the trouble is that since ruby uses select() in  
its thread scheduling, on windows, select() only works with sockets,  
not other types of file handles. (I.e. windows is broken.)

Regards,

Bill
