parallel 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Gemfile.lock +3 -1
- data/Readme.md +9 -0
- data/lib/parallel.rb +11 -6
- data/lib/parallel/version.rb +1 -1
- data/parallel.gemspec +5 -2
- data/spec/cases/map_with_processes_and_break.rb +10 -0
- data/spec/cases/map_with_threads_and_break.rb +9 -0
- data/spec/parallel_spec.rb +8 -0
- metadata +6 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -51,6 +51,14 @@ Parallel.each(User.all, :in_processes => 8) do |user|
|
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
+
### Break
|
55
|
+
|
56
|
+
```Ruby
|
57
|
+
Parallel.map(User.all) do |user|
|
58
|
+
raise Parallel::Break # -> stop all execution
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
54
62
|
Processes/Threads are workers, they grab the next piece of work when they finish
|
55
63
|
|
56
64
|
### Progress / ETA
|
@@ -90,6 +98,7 @@ Authors
|
|
90
98
|
- [Jurriaan Pruis](http://github.com/jurriaan)
|
91
99
|
- [Rob Worley](http://github.com/robworley)
|
92
100
|
- [Tasveer Singh](https://github.com/tazsingh)
|
101
|
+
- [Joachim](https://github.com/jmozmoz)
|
93
102
|
|
94
103
|
[Michael Grosser](http://grosser.it)<br/>
|
95
104
|
michael@grosser.it<br/>
|
data/lib/parallel.rb
CHANGED
@@ -6,6 +6,9 @@ module Parallel
|
|
6
6
|
class DeadWorker < Exception
|
7
7
|
end
|
8
8
|
|
9
|
+
class Break < Exception
|
10
|
+
end
|
11
|
+
|
9
12
|
class ExceptionWrapper
|
10
13
|
attr_reader :exception
|
11
14
|
def initialize(exception)
|
@@ -185,9 +188,7 @@ module Parallel
|
|
185
188
|
end
|
186
189
|
end
|
187
190
|
|
188
|
-
|
189
|
-
|
190
|
-
results
|
191
|
+
handle_exception(exception, results)
|
191
192
|
end
|
192
193
|
|
193
194
|
def work_in_processes(items, options, &blk)
|
@@ -221,9 +222,7 @@ module Parallel
|
|
221
222
|
end
|
222
223
|
end
|
223
224
|
|
224
|
-
|
225
|
-
|
226
|
-
results
|
225
|
+
handle_exception(exception, results)
|
227
226
|
end
|
228
227
|
|
229
228
|
def create_workers(items, options, &block)
|
@@ -286,6 +285,12 @@ module Parallel
|
|
286
285
|
end
|
287
286
|
end
|
288
287
|
|
288
|
+
def handle_exception(exception, results)
|
289
|
+
return nil if exception.class == Parallel::Break
|
290
|
+
raise exception if exception
|
291
|
+
results
|
292
|
+
end
|
293
|
+
|
289
294
|
# options is either a Integer or a Hash with :count
|
290
295
|
def extract_count_from_options(options)
|
291
296
|
if options.is_a?(Hash)
|
data/lib/parallel/version.rb
CHANGED
data/parallel.gemspec
CHANGED
@@ -9,6 +9,9 @@ Gem::Specification.new name, Parallel::VERSION do |s|
|
|
9
9
|
s.homepage = "https://github.com/grosser/#{name}"
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.license = "MIT"
|
12
|
-
|
13
|
-
|
12
|
+
key = File.expand_path("~/.ssh/gem-private_key.pem")
|
13
|
+
if File.exist?(key)
|
14
|
+
s.signing_key = key
|
15
|
+
s.cert_chain = ["gem-public_cert.pem"]
|
16
|
+
end
|
14
17
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
|
3
|
+
result = Parallel.map(1..100, :in_processes => 4) do |x|
|
4
|
+
sleep 0.1 # so all processes get started
|
5
|
+
print x
|
6
|
+
raise Parallel::Break if x == 1
|
7
|
+
sleep 0.1 # so no now work gets queued before Parallel::Break is raised
|
8
|
+
x
|
9
|
+
end
|
10
|
+
print " Parallel::Break raised - result #{result.inspect}"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
|
+
|
3
|
+
result = Parallel.map(1..100, :in_threads => 4) do |x|
|
4
|
+
sleep 0.1 # so all threads get started
|
5
|
+
print x
|
6
|
+
raise Parallel::Break if x == 1
|
7
|
+
sleep 0.1 # so no now work gets queued before Parallel::Break is raised
|
8
|
+
end
|
9
|
+
print " Parallel::Break raised - result #{result.inspect}"
|
data/spec/parallel_spec.rb
CHANGED
@@ -165,6 +165,14 @@ describe Parallel do
|
|
165
165
|
`ruby spec/cases/map_with_threads_and_exceptions.rb 2>&1`.should =~ /^\d{0,4} raised$/
|
166
166
|
end
|
167
167
|
|
168
|
+
it 'stops all workers when one raises Break in process' do
|
169
|
+
`ruby spec/cases/map_with_processes_and_break.rb 2>&1`.should =~ /^\d{4} Parallel::Break raised - result nil$/
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'stops all workers when one raises Break in thread' do
|
173
|
+
`ruby spec/cases/map_with_threads_and_break.rb 2>&1`.should =~ /^\d{4} Parallel::Break raised - result nil$/
|
174
|
+
end
|
175
|
+
|
168
176
|
it "can run with 0 threads" do
|
169
177
|
Thread.should_not_receive(:exclusive)
|
170
178
|
Parallel.map([1,2,3,4,5,6,7,8,9], :in_threads => 0){|x| x+2 }.should == [3,4,5,6,7,8,9,10,11]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
VHNmKzZNYWVud0FNa0FnSGRzd0dzSnp0T25ObkJhM0YKeTBrQ1NXbUs2RCt4
|
37
37
|
L1NiZlM2cjdLZTA3TVJxemlKZEI5R3VFMSswY0lSdUZoOEVRK0xONkhYQ0tN
|
38
38
|
NXBvbi9HVQp5Y3dNWGZsMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2013-03-
|
39
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
40
40
|
dependencies: []
|
41
41
|
description:
|
42
42
|
email: michael@grosser.it
|
@@ -63,7 +63,9 @@ files:
|
|
63
63
|
- spec/cases/map_with_killed_worker_before_read.rb
|
64
64
|
- spec/cases/map_with_killed_worker_before_write.rb
|
65
65
|
- spec/cases/map_with_nested_arrays_and_nil.rb
|
66
|
+
- spec/cases/map_with_processes_and_break.rb
|
66
67
|
- spec/cases/map_with_processes_and_exceptions.rb
|
68
|
+
- spec/cases/map_with_threads_and_break.rb
|
67
69
|
- spec/cases/map_with_threads_and_exceptions.rb
|
68
70
|
- spec/cases/no_dump_with_each.rb
|
69
71
|
- spec/cases/parallel_high_fork_rate.rb
|
@@ -97,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
99
|
version: '0'
|
98
100
|
segments:
|
99
101
|
- 0
|
100
|
-
hash: -
|
102
|
+
hash: -2205036652942743668
|
101
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
104
|
none: false
|
103
105
|
requirements:
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
segments:
|
108
110
|
- 0
|
109
|
-
hash: -
|
111
|
+
hash: -2205036652942743668
|
110
112
|
requirements: []
|
111
113
|
rubyforge_project:
|
112
114
|
rubygems_version: 1.8.25
|
metadata.gz.sig
CHANGED
Binary file
|