stripmem 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,11 +26,15 @@ module StripMem
26
26
  attr_reader :command, :start_time
27
27
 
28
28
  def run!
29
+ @timers = []
29
30
  EventMachine.run do
30
31
  spawn!
31
32
  channel = EM::Channel.new
32
- EM::PeriodicTimer.new(1.0) { find_children }
33
- EM::PeriodicTimer.new(0.2) { ps(channel) }
33
+ @timers = [
34
+ EM::PeriodicTimer.new(1.0) { find_children },
35
+ EM::PeriodicTimer.new(0.2) { ps(channel) },
36
+ EM::PeriodicTimer.new(1.0) { wait_child },
37
+ ]
34
38
  WebSocket.new(channel).run!
35
39
  Thread.new do
36
40
  Web.new(channel).run! # This doesn't return until sinatra exits. (Sinatra handles SIGINT.)
@@ -43,7 +47,7 @@ module StripMem
43
47
  end
44
48
 
45
49
  def kill!
46
- Process.kill('QUIT', @child.to_i)
50
+ Process.kill('QUIT', @child.to_i) unless @child_status
47
51
  rescue => e
48
52
  puts "kill #{@child.inspect}: #{e}"
49
53
  end
@@ -78,5 +82,13 @@ module StripMem
78
82
  end
79
83
  processes[@child] = command.join(' ')
80
84
  end
85
+
86
+ def wait_child
87
+ if @child_status ||= Process.waitpid2(-1, Process::WNOHANG)
88
+ @timers.each do |timer|
89
+ timer.cancel
90
+ end
91
+ end
92
+ end
81
93
  end
82
94
  end
@@ -1,3 +1,3 @@
1
1
  module StripMem
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -7,7 +7,10 @@ module StripMem
7
7
  end
8
8
 
9
9
  def run!
10
- App.run!(:port => 9999, :server => 'webrick')
10
+ puts "Starting a server on http://localhost:9999/"
11
+ App.run!(:port => 9999, :server => 'webrick') do
12
+ system "open http://localhost:9999/"
13
+ end
11
14
  end
12
15
 
13
16
  class App < Sinatra::Base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripmem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: em-websocket