process-group 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +9 -0
- data/.travis.yml +3 -1
- data/Gemfile +4 -0
- data/README.md +4 -2
- data/Rakefile +3 -1
- data/lib/process/group.rb +11 -9
- data/lib/process/group/version.rb +1 -1
- data/process-group.gemspec +3 -1
- data/spec/process/group/fork_spec.rb +3 -0
- data/spec/process/group/interrupt_spec.rb +1 -1
- data/spec/process/group/load_spec.rb +46 -0
- data/spec/process/group/process_spec.rb +57 -0
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb7a4e8773cff719edfa1b553e7773c34d6a3537
|
4
|
+
data.tar.gz: b746a13f2d670c5a3051c1d076da83b38461d5ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d475c34015705d9a7fd8fbca38bff1e1964338e9c210c6dc901da1ce40393d690cccaee4df3201ac4badff5151e9c74ef76f3c51a6f69ee2fc7d10ba7789d68
|
7
|
+
data.tar.gz: 0f9d5c41fb03e194cee54272a87a3d0c3df2f6251587648ef1cc04d3d3a9a8e5e109e0519ae62e02de460d30d92833a5f65655b0c06fe1ce7af485470de9c157
|
data/.simplecov
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
`Process::Group` allows for multiple fibers to run system processes concurrently with minimal overhead.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/ioquatix/process-group.svg
|
5
|
+
[![Build Status](https://secure.travis-ci.org/ioquatix/process-group.svg)](http://travis-ci.org/ioquatix/process-group)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/ioquatix/process-group.svg)](https://codeclimate.com/github/ioquatix/process-group)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/ioquatix/process-group/badge.svg)](https://coveralls.io/r/ioquatix/process-group)
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -101,7 +103,7 @@ If there are no running processes, this is a no-op (rather than an error).
|
|
101
103
|
|
102
104
|
#### Handling Interrupts
|
103
105
|
|
104
|
-
`Process::
|
106
|
+
`Process::Group` transparently handles `Interrupt` when raised within a `Fiber`. If `Interrupt` is raised, all children processes will be sent `kill(:INT)` and we will wait for all children to complete, but without resuming the controlling fibers. If `Interrupt` is raised during this process, children will be sent `kill(:TERM)`. After calling `Interrupt`, the fibers will not be resumed.
|
105
107
|
|
106
108
|
### Process Timeout
|
107
109
|
|
data/Rakefile
CHANGED
data/lib/process/group.rb
CHANGED
@@ -48,7 +48,8 @@ module Process
|
|
48
48
|
class Fork
|
49
49
|
def initialize(block, options, fiber = Fiber.current)
|
50
50
|
@options = options
|
51
|
-
|
51
|
+
|
52
|
+
raise ArgumentError.new("Fork requires a block!") unless @block = block
|
52
53
|
|
53
54
|
@fiber = fiber
|
54
55
|
end
|
@@ -73,9 +74,11 @@ module Process
|
|
73
74
|
end
|
74
75
|
|
75
76
|
# Create a new process group. Can specify `options[:limit]` which limits the maximum number of concurrent processes.
|
76
|
-
def initialize(
|
77
|
+
def initialize(limit: nil)
|
78
|
+
@pid = Process.pid
|
79
|
+
|
77
80
|
@queue = []
|
78
|
-
@limit =
|
81
|
+
@limit = limit
|
79
82
|
|
80
83
|
@running = {}
|
81
84
|
@fiber = nil
|
@@ -109,14 +112,11 @@ module Process
|
|
109
112
|
end.resume
|
110
113
|
end
|
111
114
|
|
112
|
-
def spawn(*arguments)
|
113
|
-
# Could be nice to use ** splat, but excludes ruby < 2.0.
|
114
|
-
options = Hash === arguments.last ? arguments.pop : {}
|
115
|
-
|
115
|
+
def spawn(*arguments, **options)
|
116
116
|
append! Command.new(arguments, options)
|
117
117
|
end
|
118
118
|
|
119
|
-
def fork(options
|
119
|
+
def fork(**options, &block)
|
120
120
|
append! Fork.new(block, options)
|
121
121
|
end
|
122
122
|
|
@@ -136,6 +136,8 @@ module Process
|
|
136
136
|
|
137
137
|
# Wait for all processes to finish, naturally would schedule any fibers which are currently blocked.
|
138
138
|
def wait
|
139
|
+
raise ArgumentError.new("Cannot call Process::Group#wait from child process!") unless @pid == Process.pid
|
140
|
+
|
139
141
|
while running?
|
140
142
|
process, status = wait_one
|
141
143
|
|
@@ -196,7 +198,7 @@ module Process
|
|
196
198
|
else
|
197
199
|
pid = process.run(:pgroup => @pgid)
|
198
200
|
end
|
199
|
-
|
201
|
+
|
200
202
|
@running[pid] = process
|
201
203
|
end
|
202
204
|
end
|
data/process-group.gemspec
CHANGED
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.required_ruby_version = '>= 2.0'
|
24
|
+
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
25
27
|
spec.add_development_dependency "rake"
|
26
28
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'process/group'
|
22
|
+
|
23
|
+
module Process::Group::LoadSpec
|
24
|
+
describe Process::Group do
|
25
|
+
it "should only run a limited number of processes" do
|
26
|
+
group = Process::Group.new(limit: 5)
|
27
|
+
|
28
|
+
expect(group.available?).to be_truthy
|
29
|
+
expect(group.blocking?).to be_falsey
|
30
|
+
|
31
|
+
5.times do
|
32
|
+
Fiber.new do
|
33
|
+
result = group.fork do
|
34
|
+
exit(0)
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(result.exitstatus).to be == 0
|
38
|
+
end.resume
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(group.blocking?).to be_truthy
|
42
|
+
|
43
|
+
group.wait
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Process::Group::ProcessSpec
|
22
|
+
describe Process do
|
23
|
+
it "default fork exit status should be 0" do
|
24
|
+
pid = fork do
|
25
|
+
end
|
26
|
+
|
27
|
+
Process.waitpid(pid)
|
28
|
+
|
29
|
+
expect($?.exitstatus).to be == 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should fork and return exit status correctly" do
|
33
|
+
pid = fork do
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
Process.waitpid(pid)
|
38
|
+
|
39
|
+
expect($?.exitstatus).to be == 1
|
40
|
+
end
|
41
|
+
|
42
|
+
# This is currently broken on Rubinius.
|
43
|
+
it "should be okay to use fork within a fiber" do
|
44
|
+
pid = nil
|
45
|
+
|
46
|
+
Fiber.new do
|
47
|
+
pid = fork do
|
48
|
+
exit(2)
|
49
|
+
end
|
50
|
+
end.resume
|
51
|
+
|
52
|
+
Process.waitpid(pid)
|
53
|
+
|
54
|
+
expect($?.exitstatus).to be == 2
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: process-group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".gitignore"
|
65
|
+
- ".simplecov"
|
65
66
|
- ".travis.yml"
|
66
67
|
- Gemfile
|
67
68
|
- README.md
|
@@ -73,6 +74,8 @@ files:
|
|
73
74
|
- spec/process/group/fork_spec.rb
|
74
75
|
- spec/process/group/interrupt_spec.rb
|
75
76
|
- spec/process/group/io_spec.rb
|
77
|
+
- spec/process/group/load_spec.rb
|
78
|
+
- spec/process/group/process_spec.rb
|
76
79
|
- spec/process/group/spawn_spec.rb
|
77
80
|
homepage: ''
|
78
81
|
licenses:
|
@@ -86,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
89
|
requirements:
|
87
90
|
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
92
|
+
version: '2.0'
|
90
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
95
|
- - ">="
|
@@ -102,4 +105,6 @@ test_files:
|
|
102
105
|
- spec/process/group/fork_spec.rb
|
103
106
|
- spec/process/group/interrupt_spec.rb
|
104
107
|
- spec/process/group/io_spec.rb
|
108
|
+
- spec/process/group/load_spec.rb
|
109
|
+
- spec/process/group/process_spec.rb
|
105
110
|
- spec/process/group/spawn_spec.rb
|