From 4b5e01a32cb005dd890c32a78cf34150efc7a208 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 9 Feb 2009 20:59:49 -0800 Subject: Avoid starting the pipe until we need it If we're running in the foreground and don't care for process manglement, then there's no need to start a pipe we won't need. --- lib/unicorn.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/unicorn.rb b/lib/unicorn.rb index cacb395..3389846 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -71,14 +71,7 @@ module Unicorn @start_ctx = DEFAULT_START_CTX.dup @start_ctx.merge!(options[:start_ctx]) if options[:start_ctx] @purgatory = [] # prevents objects in here from being GC-ed - - # this pipe is used to wake us up from select(2) in #join when signals - # are trapped. See trap_deferred - @rd_sig, @wr_sig = IO.pipe.map do |io| - set_cloexec(io) - io.nonblock = true - io - end + @rd_sig = @wr_sig = nil end # Runs the thing. Returns self so you can run join on it @@ -140,7 +133,16 @@ module Unicorn # one-at-a-time time and we'll happily drop signals in case somebody # is signalling us too often. def join + # this pipe is used to wake us up from select(2) in #join when signals + # are trapped. See trap_deferred + @rd_sig, @wr_sig = IO.pipe.map do |io| + set_cloexec(io) + io.nonblock = true + io + end unless (@rd_sig && @wr_sig) + %w(QUIT INT TERM USR1 USR2 HUP).each { |sig| trap_deferred(sig) } + begin loop do reap_all_workers @@ -346,8 +348,8 @@ module Unicorn # by the user. def init_worker_process %w(TERM INT QUIT USR1 USR2 HUP).each { |sig| trap(sig, 'IGNORE') } - @rd_sig.close - @wr_sig.close + @rd_sig.close if @rd_sig + @wr_sig.close if @wr_sig @workers.values.each { |other| other.tempfile.close rescue nil } @workers.clear @start_ctx.clear -- cgit v1.2.3-24-ge0c7