Script stops while waiting for user input from STDIN.gets
Posted
by bob c
on Stack Overflow
See other posts from Stack Overflow
or by bob c
Published on 2010-03-08T06:04:18Z
Indexed on
2010/03/08
6:06 UTC
Read the original article
Hit count: 589
I'm trying to do something like this, where I have two loops going in seperate threads. The problem I am having is that in the main thread, when I use gets and the script is waiting for user input, the other thread is stopped to wait as well.
class Server
def initialize()
@server = TCPServer.new(8080)
run
end
def run()
@thread = Thread.new(@server) { |server|
while true
newsock = server.accept
puts "some stuff after accept!"
next if !newsock
# some other stuff
end
}
end
end
def processCommand()
# some user commands here
end
test = Server.new
while true do
processCommand(STDIN.gets)
end
The above is just a sample of what I want to do.
Is there a way to make the main thread block while waiting for user input?
© Stack Overflow or respective owner