dont-stall-my-process 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 562d9b6a49097a22566602128f5a531c53e26330
4
- data.tar.gz: 689944a6f09ea614d5180ccf54e0369201f75398
3
+ metadata.gz: 647fc238f71c4c106326724b91668330a65db0e0
4
+ data.tar.gz: 3aff9c4730cf3cd90335b0af9c7585d6514104d8
5
5
  SHA512:
6
- metadata.gz: 9addba72c01ea9f16e49ebdc80ae723881472c2e528e81367e609275974811c12c8cfdd885570b2a4d5b1b06a5ea175a2d336dfd8d61a6a4051f8d89520a201d
7
- data.tar.gz: 72d8f63b14088d706a116eb38088daf5dac20a4ba0ce85eb9cca1edfad2ce5c1740104d1bd06fc212d83324bf9fc9a7d90707cdbd0b01682dcf4c9203e3fe8be
6
+ metadata.gz: 2180e9b9c5be12218edf9ee900d474270ae44f53c8c1a333c6b4ba65d7dd29b32c5bcc55007f0d59a0aa52d38a54995c0b50ac374aef53a0a3f4e1960178d251
7
+ data.tar.gz: 795e77e6ba1693ea4e42c5410a93c12ee437c80c813b3e92bb300e5e550f9241bb4b3f02e3de24ee398bc677e13cbade7a3834e2e97718397be00c09ad53d1cb
@@ -1,11 +1,11 @@
1
1
  require 'dont-stall-my-process/configuration'
2
2
  require 'dont-stall-my-process/exceptions'
3
3
  require 'dont-stall-my-process/proxy_registry'
4
+ require 'dont-stall-my-process/process_exit_handler'
4
5
  require 'dont-stall-my-process/version'
5
6
  require 'dont-stall-my-process/local/child_process'
6
7
  require 'dont-stall-my-process/local/child_process_pool'
7
8
  require 'dont-stall-my-process/local/local_proxy'
8
- require 'dont-stall-my-process/local/process_exit_handler'
9
9
  require 'dont-stall-my-process/remote/remote_application'
10
10
  require 'dont-stall-my-process/remote/remote_application_controller'
11
11
  require 'dont-stall-my-process/remote/remote_proxy'
@@ -3,8 +3,8 @@ module DontStallMyProcess
3
3
  DEFAULT_TIMEOUT = 300
4
4
 
5
5
  ATTRIBUTES = [:sigkill_only, :close_stdio, :restore_all_traps, :skip_at_exit_handlers,
6
- :process_pool_size, :subprocess_name, :after_fork_handler]
7
- attr_writer *(ATTRIBUTES - [:after_fork_handler])
6
+ :process_pool_size, :subprocess_name, :before_fork_handler, :after_fork_handler]
7
+ attr_writer *(ATTRIBUTES - [:before_fork_handler, :after_fork_handler])
8
8
 
9
9
  def initialize
10
10
  @sigkill_only = false
@@ -12,10 +12,17 @@ module DontStallMyProcess
12
12
  @restore_all_traps = false
13
13
  @skip_at_exit_handlers = false
14
14
  @process_pool_size = nil
15
+ @before_fork_handler = Proc.new {}
15
16
  @after_fork_handler = Proc.new {}
16
17
  @subprocess_name = nil
17
18
  end
18
19
 
20
+
21
+ def before_fork(p = nil, &block)
22
+ fail 'before_fork needs a block or Proc object' unless (p && p.is_a?(Proc)) || block_given?
23
+ @before_fork_handler = p || block
24
+ end
25
+
19
26
  def after_fork(p = nil, &block)
20
27
  fail 'after_fork needs a block or Proc object' unless (p && p.is_a?(Proc)) || block_given?
21
28
  @after_fork_handler = p || block
@@ -7,17 +7,16 @@ module DontStallMyProcess
7
7
  attr_reader :pid
8
8
 
9
9
  def initialize
10
- # Start RemoteApplication in child process, connect to it thru pipe.
11
10
  r, w = IO.pipe
11
+
12
+ # Call the before_fork handler now, so the client can clean up the main
13
+ # process a bit.
14
+ Configuration.before_fork_handler.call
15
+
16
+ # Start RemoteApplication in child process, connect to it thru pipe.
12
17
  @pid = fork do
13
18
  r.close
14
19
 
15
- # Disable process cleanup, otherwise killing the
16
- # subprocess (when Configuration.skip_at_exit_handlers is false) will
17
- # terminate all the other subprocesses, or at least screw with their
18
- # unix sockets.
19
- ProcessExitHandler.disable_at_exit
20
-
21
20
  app = DontStallMyProcess::Remote::RemoteApplication.new(w)
22
21
  app.loop!
23
22
  end
@@ -0,0 +1,28 @@
1
+ require 'fileutils'
2
+
3
+ module DontStallMyProcess
4
+ class ProcessExitHandler
5
+ def self.disable_at_exit
6
+ @at_exit_disabled = true
7
+ end
8
+
9
+ def self.at_exit_disabled?
10
+ @at_exit_disabled
11
+ end
12
+
13
+ at_exit do
14
+ # If we're in a subprocess, this handler should not run.
15
+ unless ProcessExitHandler.at_exit_disabled?
16
+
17
+ # Make sure we terminate all subprocesses when
18
+ # the main process exits.
19
+ Local::ChildProcessPool.each do |process|
20
+ process.quit
21
+ end
22
+
23
+ # Clean remaining unix sockets from /tmp.
24
+ FileUtils.rm(Dir["/tmp/dsmp-#{Process.pid}*"])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -11,6 +11,12 @@ module DontStallMyProcess
11
11
  end
12
12
 
13
13
  def initialize(pipe)
14
+ # Disable process cleanup, otherwise killing the
15
+ # subprocess (when Configuration.skip_at_exit_handlers is false) will
16
+ # terminate all the other subprocesses, or at least screw with their
17
+ # unix sockets.
18
+ ProcessExitHandler.disable_at_exit
19
+
14
20
  # Do not write to stdout/stderr unless requested by the client.
15
21
  if Configuration.close_stdio
16
22
  $stdout.reopen('/dev/null', 'w')
@@ -1,3 +1,3 @@
1
1
  module DontStallMyProcess
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dont-stall-my-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - FlavourSys Technology GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-08 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Executes code or native extensions in child processes and monitors their
14
14
  execution times
@@ -23,7 +23,7 @@ files:
23
23
  - lib/dont-stall-my-process/local/child_process.rb
24
24
  - lib/dont-stall-my-process/local/child_process_pool.rb
25
25
  - lib/dont-stall-my-process/local/local_proxy.rb
26
- - lib/dont-stall-my-process/local/process_exit_handler.rb
26
+ - lib/dont-stall-my-process/process_exit_handler.rb
27
27
  - lib/dont-stall-my-process/proxy_registry.rb
28
28
  - lib/dont-stall-my-process/remote/remote_application.rb
29
29
  - lib/dont-stall-my-process/remote/remote_application_controller.rb
@@ -1,30 +0,0 @@
1
- require 'fileutils'
2
-
3
- module DontStallMyProcess
4
- module Local
5
- class ProcessExitHandler
6
- def self.disable_at_exit
7
- @at_exit_disabled = true
8
- end
9
-
10
- def self.at_exit_disabled?
11
- @at_exit_disabled
12
- end
13
-
14
- at_exit do
15
- # If we're in a subprocess, this handler should not run.
16
- unless ProcessExitHandler.at_exit_disabled?
17
-
18
- # Make sure we terminate all subprocesses when
19
- # the main process exits.
20
- ChildProcessPool.each do |process|
21
- process.quit
22
- end
23
-
24
- # Clean remaining unix sockets from /tmp.
25
- FileUtils.rm(Dir["/tmp/dsmp-#{Process.pid}*"])
26
- end
27
- end
28
- end
29
- end
30
- end