Skip to content

Commit

Permalink
Refactoring signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtimberlake committed Nov 29, 2012
1 parent 30a826d commit 6898baa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/cascade/master.rb
Expand Up @@ -8,14 +8,17 @@ def initialize(worker_class=Worker)
attr_reader :worker_class attr_reader :worker_class
attr_accessor :children attr_accessor :children


CHILDREN = [] CHILDREN = []
SIG_QUEUE = [] SIG_QUEUE = []
SELF_PIPE = [] SELF_PIPE = []
QUIT_SIGNALS = [:TERM, :INT, :QUIT]
MASTER_SIGNALS = [:TTIN, :TTOU, :CHLD, :USR2]
WORKER_SIGNALS = []


def start(workers=2) def start(workers=2)
init_self_pipe! init_self_pipe!


[:TERM, :INT, :QUIT, :TTIN, :TTOU, :CHLD].each do |sig| (QUIT_SIGNALS + MASTER_SIGNALS).each do |sig|
trap(sig) do trap(sig) do
SIG_QUEUE << sig SIG_QUEUE << sig
awaken_master awaken_master
Expand Down Expand Up @@ -92,10 +95,10 @@ def reap_all_workers


def fork_worker(number) def fork_worker(number)
fork do fork do
[:TTIN, :TTOU].each do |sig| MASTER_SIGNALS.each do |sig|
trap(sig) {} trap(sig) {}
end end
[:TERM, :INT, :QUIT].each do |sig| QUIT_SIGNALS.each do |sig|
trap(sig) do trap(sig) do
$exit = true $exit = true
end end
Expand Down

0 comments on commit 6898baa

Please sign in to comment.