parallel 1.19.2 → 1.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parallel.rb +27 -28
- data/lib/parallel/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa334cb0d83b8049f260a5e6724d2fd0e65768f85afd0968a2af05d55dda4e0e
|
4
|
+
data.tar.gz: 7ba3ade3a7af4bcfe5944b8d7313b5ec6e4074d27755a83f95e4f8a01d77261e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d470562bd90ab80c66f69b9c1ab016f737bf52e091ac3027c51ea7482eaecd3bd3c186daab756c5d4276b9fb54f0e80f149a8071dc17c31a321ff4fc4d369600
|
7
|
+
data.tar.gz: f01bf1c3a052579c11c3097b02b02a4a30c8e881dbb4916c3ceba6f122aab3a40c276a1de82f7ea7d3790eeff2f994bd20283361151439a3d57b025bdd24dfc8
|
data/lib/parallel.rb
CHANGED
@@ -3,15 +3,21 @@ require 'parallel/version'
|
|
3
3
|
require 'parallel/processor_count'
|
4
4
|
|
5
5
|
module Parallel
|
6
|
-
extend
|
6
|
+
extend ProcessorCount
|
7
|
+
|
8
|
+
Stop = Object.new.freeze
|
7
9
|
|
8
10
|
class DeadWorker < StandardError
|
9
11
|
end
|
10
12
|
|
11
13
|
class Break < StandardError
|
14
|
+
attr_reader :value
|
15
|
+
def initialize(value = nil)
|
16
|
+
@value = value
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
|
-
class Kill <
|
20
|
+
class Kill < Break
|
15
21
|
end
|
16
22
|
|
17
23
|
class UndumpableException < StandardError
|
@@ -22,8 +28,6 @@ module Parallel
|
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
|
-
Stop = Object.new.freeze
|
26
|
-
|
27
31
|
class ExceptionWrapper
|
28
32
|
attr_reader :exception
|
29
33
|
def initialize(exception)
|
@@ -102,7 +106,7 @@ module Parallel
|
|
102
106
|
item, index = @mutex.synchronize do
|
103
107
|
return if @stopped
|
104
108
|
item = @lambda.call
|
105
|
-
@stopped = (item ==
|
109
|
+
@stopped = (item == Stop)
|
106
110
|
return if @stopped
|
107
111
|
[item, @index += 1]
|
108
112
|
end
|
@@ -230,12 +234,12 @@ module Parallel
|
|
230
234
|
|
231
235
|
def any?(*args, &block)
|
232
236
|
raise "You must provide a block when calling #any?" if block.nil?
|
233
|
-
!each(*args) { |*a| raise
|
237
|
+
!each(*args) { |*a| raise Kill if block.call(*a) }
|
234
238
|
end
|
235
239
|
|
236
240
|
def all?(*args, &block)
|
237
241
|
raise "You must provide a block when calling #all?" if block.nil?
|
238
|
-
!!each(*args) { |*a| raise
|
242
|
+
!!each(*args) { |*a| raise Kill unless block.call(*a) }
|
239
243
|
end
|
240
244
|
|
241
245
|
def each_with_index(array, options={}, &block)
|
@@ -270,16 +274,18 @@ module Parallel
|
|
270
274
|
options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
|
271
275
|
add_progress_bar!(job_factory, options)
|
272
276
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
277
|
+
result =
|
278
|
+
if size == 0
|
279
|
+
work_direct(job_factory, options, &block)
|
280
|
+
elsif method == :in_threads
|
281
|
+
work_in_threads(job_factory, options.merge(:count => size), &block)
|
282
|
+
else
|
283
|
+
work_in_processes(job_factory, options.merge(:count => size), &block)
|
284
|
+
end
|
285
|
+
|
286
|
+
return result.value if result.is_a?(Break)
|
287
|
+
raise result if result.is_a?(Exception)
|
288
|
+
options[:return_results] ? result : source
|
283
289
|
end
|
284
290
|
|
285
291
|
def map_with_index(array, options={}, &block)
|
@@ -340,7 +346,7 @@ module Parallel
|
|
340
346
|
rescue
|
341
347
|
exception = $!
|
342
348
|
end
|
343
|
-
|
349
|
+
exception || results
|
344
350
|
ensure
|
345
351
|
self.worker_number = nil
|
346
352
|
end
|
@@ -367,7 +373,7 @@ module Parallel
|
|
367
373
|
end
|
368
374
|
end
|
369
375
|
|
370
|
-
|
376
|
+
exception || results
|
371
377
|
end
|
372
378
|
|
373
379
|
def work_in_processes(job_factory, options, &blk)
|
@@ -401,7 +407,7 @@ module Parallel
|
|
401
407
|
results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
|
402
408
|
rescue StandardError => e
|
403
409
|
exception = e
|
404
|
-
if
|
410
|
+
if Kill === exception
|
405
411
|
(workers - [worker]).each do |w|
|
406
412
|
w.thread.kill if w.thread
|
407
413
|
UserInterruptHandler.kill(w.pid)
|
@@ -414,8 +420,7 @@ module Parallel
|
|
414
420
|
end
|
415
421
|
end
|
416
422
|
end
|
417
|
-
|
418
|
-
handle_exception(exception, results)
|
423
|
+
exception || results
|
419
424
|
end
|
420
425
|
|
421
426
|
def replace_worker(job_factory, workers, i, options, blk)
|
@@ -484,12 +489,6 @@ module Parallel
|
|
484
489
|
end
|
485
490
|
end
|
486
491
|
|
487
|
-
def handle_exception(exception, results)
|
488
|
-
return nil if [Parallel::Break, Parallel::Kill].include? exception.class
|
489
|
-
raise exception if exception
|
490
|
-
results
|
491
|
-
end
|
492
|
-
|
493
492
|
# options is either a Integer or a Hash with :count
|
494
493
|
def extract_count_from_options(options)
|
495
494
|
if options.is_a?(Hash)
|
data/lib/parallel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -25,8 +25,8 @@ licenses:
|
|
25
25
|
- MIT
|
26
26
|
metadata:
|
27
27
|
bug_tracker_uri: https://github.com/grosser/parallel/issues
|
28
|
-
documentation_uri: https://github.com/grosser/parallel/blob/v1.
|
29
|
-
source_code_uri: https://github.com/grosser/parallel/tree/v1.
|
28
|
+
documentation_uri: https://github.com/grosser/parallel/blob/v1.20.1/Readme.md
|
29
|
+
source_code_uri: https://github.com/grosser/parallel/tree/v1.20.1
|
30
30
|
wiki_uri: https://github.com/grosser/parallel/wiki
|
31
31
|
post_install_message:
|
32
32
|
rdoc_options: []
|
@@ -36,7 +36,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
39
|
+
version: '2.4'
|
40
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|