parallel 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -1
- data/VERSION +1 -1
- data/lib/parallel.rb +3 -2
- data/parallel.gemspec +19 -17
- data/spec/cases/cloeses_processes_at_runtime.rb +12 -0
- data/spec/cases/{parallel_each.rb → each.rb} +0 -1
- data/spec/parallel_spec.rb +5 -1
- metadata +20 -18
data/README.markdown
CHANGED
@@ -45,7 +45,8 @@ Authors
|
|
45
45
|
=======
|
46
46
|
|
47
47
|
###Contributors (alphabetical)
|
48
|
-
- [
|
48
|
+
- [Przemyslaw Wroblewski](http://github.com/lowang)
|
49
|
+
- [TJ Holowaychuk](http://vision-media.ca/)
|
49
50
|
|
50
51
|
[Michael Grosser](http://pragmatig.wordpress.com)
|
51
52
|
grosser.michael@gmail.com
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/parallel.rb
CHANGED
@@ -24,8 +24,9 @@ class Parallel
|
|
24
24
|
count ||= processor_count
|
25
25
|
preserve_results = (options[:preserve_results] != false)
|
26
26
|
|
27
|
-
pipes = fork_and_start_writing(count, :preserve_results => preserve_results, &block)
|
27
|
+
pipes, pids = fork_and_start_writing(count, :preserve_results => preserve_results, &block)
|
28
28
|
out = read_from_pipes(pipes)
|
29
|
+
pids.each { |pid| Process.wait(pid) }
|
29
30
|
out.map{|x| deserialize(x) } if preserve_results
|
30
31
|
end
|
31
32
|
|
@@ -108,7 +109,7 @@ class Parallel
|
|
108
109
|
write.close
|
109
110
|
end
|
110
111
|
kill_on_ctrl_c(pids)
|
111
|
-
reads
|
112
|
+
[reads, pids]
|
112
113
|
end
|
113
114
|
|
114
115
|
def self.do_in_new_process(work_item, options)
|
data/parallel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{parallel}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.2"
|
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 = %q{2010-
|
12
|
+
s.date = %q{2010-05-11}
|
13
13
|
s.email = %q{grosser.michael@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
@@ -20,11 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
"VERSION",
|
21
21
|
"lib/parallel.rb",
|
22
22
|
"parallel.gemspec",
|
23
|
+
"spec/cases/cloeses_processes_at_runtime.rb",
|
24
|
+
"spec/cases/each.rb",
|
23
25
|
"spec/cases/each_with_index.rb",
|
24
26
|
"spec/cases/map_with_index.rb",
|
25
27
|
"spec/cases/map_with_index_empty.rb",
|
26
28
|
"spec/cases/no_dump_with_each.rb",
|
27
|
-
"spec/cases/parallel_each.rb",
|
28
29
|
"spec/cases/parallel_high_fork_rate.rb",
|
29
30
|
"spec/cases/parallel_influence_outside_data.rb",
|
30
31
|
"spec/cases/parallel_map.rb",
|
@@ -47,24 +48,25 @@ Gem::Specification.new do |s|
|
|
47
48
|
s.summary = %q{Run any kind of code in parallel processes}
|
48
49
|
s.test_files = [
|
49
50
|
"spec/spec_helper.rb",
|
50
|
-
"spec/
|
51
|
-
"spec/cases/map_with_index_empty.rb",
|
52
|
-
"spec/cases/parallel_map_uneven.rb",
|
53
|
-
"spec/cases/parallel_map_range.rb",
|
54
|
-
"spec/cases/map_with_index.rb",
|
55
|
-
"spec/cases/parallel_with_set_processes.rb",
|
56
|
-
"spec/cases/no_dump_with_each.rb",
|
57
|
-
"spec/cases/each_with_index.rb",
|
58
|
-
"spec/cases/parallel_start_and_kill.rb",
|
59
|
-
"spec/cases/parallel_raise.rb",
|
51
|
+
"spec/parallel_spec.rb",
|
60
52
|
"spec/cases/parallel_sleeping_2.rb",
|
61
|
-
"spec/cases/
|
62
|
-
"spec/cases/parallel_influence_outside_data.rb",
|
53
|
+
"spec/cases/no_dump_with_each.rb",
|
63
54
|
"spec/cases/parallel_high_fork_rate.rb",
|
55
|
+
"spec/cases/map_with_index.rb",
|
56
|
+
"spec/cases/parallel_with_set_processes.rb",
|
64
57
|
"spec/cases/parallel_map.rb",
|
65
|
-
"spec/cases/
|
58
|
+
"spec/cases/parallel_influence_outside_data.rb",
|
59
|
+
"spec/cases/parallel_start_and_kill.rb",
|
60
|
+
"spec/cases/parallel_map_uneven.rb",
|
66
61
|
"spec/cases/parallel_map_sleeping.rb",
|
67
|
-
"spec/
|
62
|
+
"spec/cases/cloeses_processes_at_runtime.rb",
|
63
|
+
"spec/cases/parallel_with_detected_cpus.rb",
|
64
|
+
"spec/cases/each.rb",
|
65
|
+
"spec/cases/map_with_index_empty.rb",
|
66
|
+
"spec/cases/parallel_raise.rb",
|
67
|
+
"spec/cases/each_with_index.rb",
|
68
|
+
"spec/cases/parallel_with_nil_uses_detected_cpus.rb",
|
69
|
+
"spec/cases/parallel_map_range.rb"
|
68
70
|
]
|
69
71
|
|
70
72
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/spec_helper.rb'
|
2
|
+
cmd = "ps uaxw|grep ruby|wc -l"
|
3
|
+
|
4
|
+
processes_before = `#{cmd}`.to_i
|
5
|
+
Parallel.each((0..10).to_a, :in_processes => 5) { |a| a*2 }
|
6
|
+
processes_after = `#{cmd}`.to_i
|
7
|
+
|
8
|
+
if processes_before == processes_after
|
9
|
+
print 'OK'
|
10
|
+
else
|
11
|
+
print "FAIL: before:#{processes_before} -- after:#{processes_after}"
|
12
|
+
end
|
data/spec/parallel_spec.rb
CHANGED
@@ -50,6 +50,10 @@ describe Parallel do
|
|
50
50
|
it 'can handle to high fork rate' do
|
51
51
|
`ruby spec/cases/parallel_high_fork_rate.rb`.should == 'OK'
|
52
52
|
end
|
53
|
+
|
54
|
+
it 'it does not leave processes behind while running' do
|
55
|
+
`ruby spec/cases/cloeses_processes_at_runtime.rb`.should == 'OK'
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
describe :in_threads do
|
@@ -114,7 +118,7 @@ describe Parallel do
|
|
114
118
|
|
115
119
|
describe :each do
|
116
120
|
it "returns original array, works like map" do
|
117
|
-
`ruby spec/cases/
|
121
|
+
`ruby spec/cases/each.rb`.should == 'a b c d'
|
118
122
|
end
|
119
123
|
|
120
124
|
it "does not use marshal_dump" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 2
|
9
|
+
version: 0.4.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Grosser
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-11 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -32,11 +32,12 @@ files:
|
|
32
32
|
- VERSION
|
33
33
|
- lib/parallel.rb
|
34
34
|
- parallel.gemspec
|
35
|
+
- spec/cases/cloeses_processes_at_runtime.rb
|
36
|
+
- spec/cases/each.rb
|
35
37
|
- spec/cases/each_with_index.rb
|
36
38
|
- spec/cases/map_with_index.rb
|
37
39
|
- spec/cases/map_with_index_empty.rb
|
38
40
|
- spec/cases/no_dump_with_each.rb
|
39
|
-
- spec/cases/parallel_each.rb
|
40
41
|
- spec/cases/parallel_high_fork_rate.rb
|
41
42
|
- spec/cases/parallel_influence_outside_data.rb
|
42
43
|
- spec/cases/parallel_map.rb
|
@@ -83,21 +84,22 @@ specification_version: 3
|
|
83
84
|
summary: Run any kind of code in parallel processes
|
84
85
|
test_files:
|
85
86
|
- spec/spec_helper.rb
|
86
|
-
- spec/
|
87
|
-
- spec/cases/map_with_index_empty.rb
|
88
|
-
- spec/cases/parallel_map_uneven.rb
|
89
|
-
- spec/cases/parallel_map_range.rb
|
90
|
-
- spec/cases/map_with_index.rb
|
91
|
-
- spec/cases/parallel_with_set_processes.rb
|
92
|
-
- spec/cases/no_dump_with_each.rb
|
93
|
-
- spec/cases/each_with_index.rb
|
94
|
-
- spec/cases/parallel_start_and_kill.rb
|
95
|
-
- spec/cases/parallel_raise.rb
|
87
|
+
- spec/parallel_spec.rb
|
96
88
|
- spec/cases/parallel_sleeping_2.rb
|
97
|
-
- spec/cases/
|
98
|
-
- spec/cases/parallel_influence_outside_data.rb
|
89
|
+
- spec/cases/no_dump_with_each.rb
|
99
90
|
- spec/cases/parallel_high_fork_rate.rb
|
91
|
+
- spec/cases/map_with_index.rb
|
92
|
+
- spec/cases/parallel_with_set_processes.rb
|
100
93
|
- spec/cases/parallel_map.rb
|
101
|
-
- spec/cases/
|
94
|
+
- spec/cases/parallel_influence_outside_data.rb
|
95
|
+
- spec/cases/parallel_start_and_kill.rb
|
96
|
+
- spec/cases/parallel_map_uneven.rb
|
102
97
|
- spec/cases/parallel_map_sleeping.rb
|
103
|
-
- spec/
|
98
|
+
- spec/cases/cloeses_processes_at_runtime.rb
|
99
|
+
- spec/cases/parallel_with_detected_cpus.rb
|
100
|
+
- spec/cases/each.rb
|
101
|
+
- spec/cases/map_with_index_empty.rb
|
102
|
+
- spec/cases/parallel_raise.rb
|
103
|
+
- spec/cases/each_with_index.rb
|
104
|
+
- spec/cases/parallel_with_nil_uses_detected_cpus.rb
|
105
|
+
- spec/cases/parallel_map_range.rb
|