parallel 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/parallel.rb +14 -6
- data/parallel.gemspec +9 -7
- data/spec/cases/count_open_pipes.rb +6 -0
- data/spec/cases/parallel_sleeping_2.rb +1 -1
- data/spec/parallel_spec.rb +6 -0
- metadata +7 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.11
|
data/lib/parallel.rb
CHANGED
@@ -149,11 +149,8 @@ class Parallel
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
ensure
|
152
|
-
worker
|
153
|
-
worker[:
|
154
|
-
|
155
|
-
# if it goes zombie, rather wait here to be able to debug
|
156
|
-
wait_for_process worker[:pid]
|
152
|
+
close_pipes(worker)
|
153
|
+
wait_for_process worker[:pid] # if it goes zombie, rather wait here to be able to debug
|
157
154
|
end
|
158
155
|
end
|
159
156
|
|
@@ -163,7 +160,11 @@ class Parallel
|
|
163
160
|
end
|
164
161
|
|
165
162
|
def self.create_workers(items, options, &block)
|
166
|
-
workers =
|
163
|
+
workers = []
|
164
|
+
Array.new(options[:count]).each do
|
165
|
+
workers << worker(items, options.merge(:started_workers => workers), &block)
|
166
|
+
end
|
167
|
+
|
167
168
|
pids = workers.map{|worker| worker[:pid] }
|
168
169
|
kill_on_ctrl_c(pids)
|
169
170
|
workers
|
@@ -178,6 +179,8 @@ class Parallel
|
|
178
179
|
|
179
180
|
pid = Process.fork do
|
180
181
|
begin
|
182
|
+
options.delete(:started_workers).each{|w| close_pipes w }
|
183
|
+
|
181
184
|
parent_write.close
|
182
185
|
parent_read.close
|
183
186
|
|
@@ -194,6 +197,11 @@ class Parallel
|
|
194
197
|
{:read => parent_read, :write => parent_write, :pid => pid}
|
195
198
|
end
|
196
199
|
|
200
|
+
def self.close_pipes(worker)
|
201
|
+
worker[:read].close
|
202
|
+
worker[:write].close
|
203
|
+
end
|
204
|
+
|
197
205
|
def self.process_incoming_jobs(read, write, items, options, &block)
|
198
206
|
while input = read.gets and input != "\n"
|
199
207
|
index = decode(input.chomp)
|
data/parallel.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.5.
|
7
|
+
s.name = "parallel"
|
8
|
+
s.version = "0.5.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date =
|
13
|
-
s.email =
|
12
|
+
s.date = "2011-12-08"
|
13
|
+
s.email = "grosser.michael@gmail.com"
|
14
14
|
s.files = [
|
15
15
|
"Gemfile",
|
16
16
|
"Gemfile.lock",
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
"lib/parallel.rb",
|
21
21
|
"parallel.gemspec",
|
22
22
|
"spec/cases/closes_processes_at_runtime.rb",
|
23
|
+
"spec/cases/count_open_pipes.rb",
|
23
24
|
"spec/cases/each.rb",
|
24
25
|
"spec/cases/each_with_index.rb",
|
25
26
|
"spec/cases/host_os_override_processor_count.rb",
|
@@ -44,12 +45,12 @@ Gem::Specification.new do |s|
|
|
44
45
|
"spec/parallel_spec.rb",
|
45
46
|
"spec/spec_helper.rb"
|
46
47
|
]
|
47
|
-
s.homepage =
|
48
|
+
s.homepage = "http://github.com/grosser/parallel"
|
48
49
|
s.licenses = ["MIT"]
|
49
50
|
s.rdoc_options = ["--charset=UTF-8"]
|
50
51
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version =
|
52
|
-
s.summary =
|
52
|
+
s.rubygems_version = "1.8.12"
|
53
|
+
s.summary = "Run any kind of code in parallel processes"
|
53
54
|
s.test_files = [
|
54
55
|
"spec/spec_helper.rb",
|
55
56
|
"spec/parallel_spec.rb",
|
@@ -57,6 +58,7 @@ Gem::Specification.new do |s|
|
|
57
58
|
"spec/cases/parallel_map_range.rb",
|
58
59
|
"spec/cases/map_with_threads_and_exceptions.rb",
|
59
60
|
"spec/cases/parallel_influence_outside_data.rb",
|
61
|
+
"spec/cases/count_open_pipes.rb",
|
60
62
|
"spec/cases/parallel_with_set_processes.rb",
|
61
63
|
"spec/cases/parallel_with_detected_cpus.rb",
|
62
64
|
"spec/cases/parallel_start_and_kill.rb",
|
data/spec/parallel_spec.rb
CHANGED
@@ -78,6 +78,12 @@ describe Parallel do
|
|
78
78
|
it 'does not leave processes behind while running' do
|
79
79
|
`ruby spec/cases/closes_processes_at_runtime.rb`.should == 'OK'
|
80
80
|
end
|
81
|
+
|
82
|
+
it "does not open unnecessary pipes" do
|
83
|
+
open_pipes = `lsof | grep pipe | wc -l`.to_i
|
84
|
+
max_pipes = `ruby spec/cases/count_open_pipes.rb`.to_i
|
85
|
+
(max_pipes - open_pipes).should < 400
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
89
|
describe :in_threads do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 11
|
10
|
+
version: 0.5.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-12-08 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
21
|
description:
|
@@ -36,6 +35,7 @@ files:
|
|
36
35
|
- lib/parallel.rb
|
37
36
|
- parallel.gemspec
|
38
37
|
- spec/cases/closes_processes_at_runtime.rb
|
38
|
+
- spec/cases/count_open_pipes.rb
|
39
39
|
- spec/cases/each.rb
|
40
40
|
- spec/cases/each_with_index.rb
|
41
41
|
- spec/cases/host_os_override_processor_count.rb
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- spec/cases/parallel_with_set_processes.rb
|
60
60
|
- spec/parallel_spec.rb
|
61
61
|
- spec/spec_helper.rb
|
62
|
-
has_rdoc: true
|
63
62
|
homepage: http://github.com/grosser/parallel
|
64
63
|
licenses:
|
65
64
|
- MIT
|
@@ -89,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
88
|
requirements: []
|
90
89
|
|
91
90
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.8.12
|
93
92
|
signing_key:
|
94
93
|
specification_version: 3
|
95
94
|
summary: Run any kind of code in parallel processes
|
@@ -100,6 +99,7 @@ test_files:
|
|
100
99
|
- spec/cases/parallel_map_range.rb
|
101
100
|
- spec/cases/map_with_threads_and_exceptions.rb
|
102
101
|
- spec/cases/parallel_influence_outside_data.rb
|
102
|
+
- spec/cases/count_open_pipes.rb
|
103
103
|
- spec/cases/parallel_with_set_processes.rb
|
104
104
|
- spec/cases/parallel_with_detected_cpus.rb
|
105
105
|
- spec/cases/parallel_start_and_kill.rb
|