Skip to content

Commit 2cd5061

Browse files
Merge pull request #24 from santhanakarthikeyan/replace_open3_with_posix_spawn
Replaced Open3 with Posix-spawn to reduce process memory leak
2 parents 7da779e + 26e57ff commit 2cd5061

File tree

8 files changed

+34
-7
lines changed

8 files changed

+34
-7
lines changed

.install_dependencies.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#/usr/bin/env sh
2+
3+
bazaar_plugins_path=`bzr --version | awk '/bzrlib:/ {print $2}'`
4+
5+
cd "$bazaar_plugins_path/plugins"
6+
7+
sudo bzr branch lp:bzr-xmloutput
8+
9+
sudo mv bzr-xmloutput xmloutput
10+
11+
cd xmloutput
12+
13+
python setup.py build_ext -i

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.0

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: ruby
2+
install:
3+
- gem install posix-spawn
4+
- sh .install_dependencies.sh

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ hg 1.1.2
4949
If you are using CVS instead of CVSNT, you can potentially try creating
5050
a shell alias or symlink mapping 'cvsnt' to 'cvs'.
5151

52+
Ohloh SCM uses [posix-spawn](https://github.com/rtomayko/posix-spawn) to
53+
execute commands so ensure *posix-spawn* gem is installed
54+
55+
``gem install posix-spawn``
56+
57+
5258
## Usage with Bundler
5359

5460
```
5561
gem 'ohloh_scm', git: 'https://github.com/blackducksw/ohloh_scm/', require: 'scm'
62+
gem 'posix-spawn'
5663
```
5764
## Running
5865

lib/ohloh_scm/adapters/bzrlib/bzrlib_pipe_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'rubygems'
2-
require 'open4'
2+
require 'posix/spawn'
33

44
class BzrPipeClient
55
def initialize(repository_url)
@@ -8,7 +8,7 @@ def initialize(repository_url)
88
end
99

1010
def start
11-
@pid, @stdin, @stdout, @stderr = Open4::popen4 "python #{@py_script}"
11+
@pid, @stdin, @stdout, @stderr = POSIX::Spawn::popen4 "python #{@py_script}"
1212
open_repository
1313
end
1414

lib/ohloh_scm/adapters/hglib/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require 'rubygems'
2-
require 'open4'
2+
require 'posix/spawn'
33

44
class HglibClient
55
def initialize(repository_url)
@@ -8,7 +8,7 @@ def initialize(repository_url)
88
end
99

1010
def start
11-
@pid, @stdin, @stdout, @stderr = Open4::popen4 "python #{@py_script}"
11+
@pid, @stdin, @stdout, @stderr = POSIX::Spawn::popen4 "python #{@py_script}"
1212
open_repository
1313
end
1414

lib/ohloh_scm/shellout.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'rubygems'
22
require 'stringio'
3-
require 'open3'
3+
require 'posix/spawn'
44

55
class Shellout
66

@@ -9,9 +9,9 @@ def self.relay src, dst
99
end
1010

1111
def self.execute(cmd)
12-
out, err, exit_status = Open3.capture3(cmd)
12+
posix_spawn = POSIX::Spawn::Child.new(cmd)
1313

14-
return exit_status, out, err
14+
return posix_spawn.status, posix_spawn.out, posix_spawn.err
1515
end
1616

1717
def run(cmd)

ohloh_scm.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
1616
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
1717
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
1818
gem.require_paths = %w(lib)
19+
20+
gem.add_runtime_dependency 'posix-spawn', '~> 0.3'
1921
end

0 commit comments

Comments
 (0)