Permalink
Browse files

Refactoring signal handling

  • Loading branch information...
1 parent 30a826d commit 6898baa524bd0022586e02aa80cfa5979f7f2cd8 @andrewtimberlake committed Nov 29, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/cascade/master.rb
View
@@ -8,14 +8,17 @@ def initialize(worker_class=Worker)
attr_reader :worker_class
attr_accessor :children
- CHILDREN = []
- SIG_QUEUE = []
- SELF_PIPE = []
+ CHILDREN = []
+ SIG_QUEUE = []
+ SELF_PIPE = []
+ QUIT_SIGNALS = [:TERM, :INT, :QUIT]
+ MASTER_SIGNALS = [:TTIN, :TTOU, :CHLD, :USR2]
+ WORKER_SIGNALS = []
def start(workers=2)
init_self_pipe!
- [:TERM, :INT, :QUIT, :TTIN, :TTOU, :CHLD].each do |sig|
+ (QUIT_SIGNALS + MASTER_SIGNALS).each do |sig|
trap(sig) do
SIG_QUEUE << sig
awaken_master
@@ -92,10 +95,10 @@ def reap_all_workers
def fork_worker(number)
fork do
- [:TTIN, :TTOU].each do |sig|
+ MASTER_SIGNALS.each do |sig|
trap(sig) {}
end
- [:TERM, :INT, :QUIT].each do |sig|
+ QUIT_SIGNALS.each do |sig|
trap(sig) do
$exit = true
end

0 comments on commit 6898baa

Please sign in to comment.