From: "Iñaki Baz Castillo" Date: 2008-03-27T23:38:07+09:00 Subject: Re: "loop do IO.select([io], nil, nil)" eats 95% of CPU, any other way? 2008/3/27, Marcelo : > > So I don't know why but using GServer the main loop runs all the time > > while witout using GServer it doesn't occur ¿? > > > Because... > > > > > def serve(io) > > > > > > puts "------------ serve(io) -------------" > > > loop do > > > p "-- second loop --" > > > > > > ready, = select([io], nil, nil, nil).first > > > This will block if there's no data available but the file descriptor > hasn't reached EOF. It was a failure of me, since my code is based in a chat server example I found in a web. Using GServer is not needed at all to use "select". > Note that GServer.start will spawn a new thread, which handles all the > incoming connections. It will spawn a new thread for each new > connection, so your "serve" method has to handle it and then exit, it > doesn't make sense for it to keep lingering around after the client has > gone away. > > You can also replace your main loop by server.join. Great! I've used "server.join" instead of the loop and now the Ruby process doesn't eat CPU :) Thanks a lot! -- Iñaki Baz Castillo