From eba0c0df0bc863973bfc597470ef98f4d0428099 Mon Sep 17 00:00:00 2001 From: fbt Date: Mon, 21 Nov 2016 18:12:50 +0300 Subject: [PATCH] instance collector Signed-off-by: fbt --- moltenbar | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/moltenbar b/moltenbar index 9c98be4..5f8d163 100755 --- a/moltenbar +++ b/moltenbar @@ -4,6 +4,14 @@ $PROGRAM_NAME = "moltenbar" # Base worker class class Worker + @@collector = [] + + class << self + def instances + return @@collector + end + end + def initialize(config, name, pipe) @config = config @name = name @@ -20,7 +28,9 @@ class Worker mainloop() end - return @wpid + @@collector << self + + return nil end def mainloop() @@ -30,10 +40,6 @@ class Worker end end - def get_pid() - return @wpid - end - def kill() begin if Process.getpgid(@wpid) == Process.getpgid($$) @@ -89,8 +95,8 @@ class Template end # Kill the workers. -def cleanup(workers) - for w in workers do +def cleanup + Worker.instances.each do |w| w.kill end @@ -105,7 +111,6 @@ require 'erb' require 'yaml' require 'optparse' -workers = [] panel_data = {} options = {} @@ -141,14 +146,11 @@ end pipe_r, pipe_w = IO.pipe Modules.get.each do |k, v| - m = Object.const_get(v).new(config, k, pipe_w) - workers << m - - m.run + Object.const_get(v).new(config, k, pipe_w).run end -Signal.trap("INT") do cleanup(workers); end -Signal.trap("TERM") do cleanup(workers); end +Signal.trap("INT") do cleanup; end +Signal.trap("TERM") do cleanup; end if config['geometry'] == nil config['gap'] ||= 0 @@ -179,9 +181,7 @@ printf("Launching lemonbar as:\n %s\n", lemonbar_cmd.join(" ")) IO.popen(lemonbar_cmd, "w+") do |pipe_lb| pipe_lb.sync = true - sys = DoSystem.new("system", pipe_lb) - workers << sys - sys.run() + DoSystem.new("system", pipe_lb).run pipe_r.each do |line| mod_name, data = line.chomp.split("\0")