From a764983fccd6cce64043d76e09a5e1718e7f8fd6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Oct 2009 22:42:56 -0700 Subject: refactor graceful shutdowns again, harder We use the "G" global constant from the Rev model everywhere to simplify things a little. Test cases are more consistent now, too. --- lib/rainbows/thread_pool.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'lib/rainbows/thread_pool.rb') diff --git a/lib/rainbows/thread_pool.rb b/lib/rainbows/thread_pool.rb index c742e5d..30e8f69 100644 --- a/lib/rainbows/thread_pool.rb +++ b/lib/rainbows/thread_pool.rb @@ -30,7 +30,7 @@ module Rainbows pool = (1..worker_connections).map { new_worker_thread } m = 0 - while LISTENERS.first && master_pid == Process.ppid + while G.alive && master_pid == Process.ppid pool.each do |thr| worker.tmp.chmod(m = 0 == m ? 1 : 0) # if any worker dies, something is serious wrong, bail @@ -44,21 +44,20 @@ module Rainbows Thread.new { begin begin - ret = IO.select(LISTENERS, nil, nil, timeout) or next - ret.first.each do |sock| - begin - process_client(sock.accept_nonblock) - rescue Errno::EAGAIN, Errno::ECONNABORTED - end - end + ret = IO.select(LISTENERS, nil, nil, 1) and + ret.first.each do |sock| + begin + process_client(sock.accept_nonblock) + rescue Errno::EAGAIN, Errno::ECONNABORTED + end + end rescue Errno::EINTR - next rescue Errno::EBADF, TypeError break end rescue Object => e listen_loop_error(e) - end while ! Thread.current[:quit] && LISTENERS.first + end while G.alive } end -- cgit v1.2.3-24-ge0c7